• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

help with a vba excel do until loop|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / help with a vba excel do until loop|VBA & Macros|Excel Forum|My Online Training Hub

office scripts course

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & Macroshelp with a vba excel do until loop
sp_PrintTopic sp_TopicIcon
help with a vba excel do until loop
Avatar
Larry Bryan

New Member
Members
Level 0
Forum Posts: 2
Member Since:
September 18, 2019
sp_UserOfflineSmall Offline
1
September 18, 2019 - 10:46 pm
sp_Permalink sp_Print

I need help with a loop that will end when the following vba script will reach a blank cell in column A.

whal the loop does is copy the time in cell D1 to D2 and D3 to D4 and so on until a blank Cell in column A is reached

Thank's in advance for any help provided.

Larry

Application.CutCopyMode = False

    ActiveCell.FormulaR1C1 = "=R[-1]C"

    Range("D4").Select

    Application.CutCopyMode = False

    ActiveCell.FormulaR1C1 = "=R[-1]C"

    Range("D6").Select

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1548
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
September 19, 2019 - 9:14 am
sp_Permalink sp_Print

Hi Larry,

You can use something like this

   Sub copystuff()

      Dim i As Long
      i = 0

      While Range("A1").Offset(i, 0).Value <> ""

         INSERT YOUR CODE HERE

         i = i + 1

      Wend

   End Sub

Without seeing your data I can't be more specific.  By seeing it I could maybe offer some suggestions as to how to copy the data more efficiently.

Regards

Phil

Avatar
Larry Bryan

New Member
Members
Level 0
Forum Posts: 2
Member Since:
September 18, 2019
sp_UserOfflineSmall Offline
3
September 19, 2019 - 9:58 am
sp_Permalink sp_Print

Hi Phil

Here is some sample data and what I am trying to do has been done in column D2 and D4.

what has been done is I copied D1 to D2 and D3 to D4.

Now I want to copy that formula  (all odd number rows in column D to the even number rows in column D) down the entire column and end when I get to the end of the column.

I guess that the macro could end at the first blank cell in column A.

I do all right using the macro recorder but I can't seem to figure out how to start and  stop a loop function.

Any help you can give (an old man 84yrs) will be greatly appreciated.

Thanks for the reply.

Larry

311 57 UL Monroe 12:00 PM
312 -19 Iowa State 12:00 PM
313 60 Miami Ohio 3:30 PM
314 -38 Ohio State 3:30 PM
315 62 Charlotte 7:30 PM
316 -41 Clemson  
317 59.5 Connecticut 12:00 PM
318 -26.5 Indiana  
319 -10 Central Florida 3:30 PM
320 58 Pittsburgh  
321 65 UL Lafayette 2:00 PM
322 -3.5 Ohio  
323 -10 Nebraska 8:00 PM
324 63 Illinois  
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1548
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
4
September 19, 2019 - 10:42 am
sp_Permalink sp_Print

Hi Larry,

This code will do what you want.  It uses FillDown to fill an empty cell with the value above it

   Sub FillDown()

      Dim i As Long
      i = 2

         While Range("A" & i).Value <> ""

            Range("D" & i).FillDown

            i = i + 2

         Wend

   End Sub

You can do this by hand too by selecting an empty cell e.g. D2 and using the Fill Down shortcut CTRL+D.  Here's a list of useful keyboard shortcuts for Excel.

Please see attached file for working code.

Great to hear that at 84 you are still learning 🙂

Regards

Phil

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Susan VanRiper, QSolutions Group
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
jaryszek: 183
Newest Members:
Herbie Key
Trevor Pindling
Stevan Kanjo
Erin Sheldon
Nikita Bhatia
Sheilah Taylor
Clare Webber
David Jenssen
Dominic Brosnahan
Young You
Forum Stats:
Groups: 3
Forums: 24
Topics: 6526
Posts: 28575

 

Member Stats:
Guest Posters: 49
Members: 32809
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.