• 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
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

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
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
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: 1510
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: 1510
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: Andy Kirby, Ben Hughes, Ramon Lagos, Shawn Barwick
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
yashal minahil
Oluwadamilola Ogun
Yannik H
dectator mang
Francis Drouillard
Orlando Inocente
Jovitha Clemence
Maloxat Axmatovna
Ricardo Freitas
Marko Meglic
Forum Stats:
Groups: 3
Forums: 24
Topics: 6201
Posts: 27185

 

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

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • 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
 

Company

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

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.