• 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

Macro to fill one row based on the last cell used in the previous row|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Macro to fill one row based on the last cell used in the previous row|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 & MacrosMacro to fill one row based on the …
sp_PrintTopic sp_TopicIcon
Macro to fill one row based on the last cell used in the previous row
Avatar
Brenda Delorme

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
June 16, 2015
sp_UserOfflineSmall Offline
1
July 1, 2016 - 9:31 am
sp_Permalink sp_Print

Scenerio:

Col M has data in Rows 6-10.

I would like to take a value from Col. N, row 5  and paste it into rows 6-10 of the same column (N).

Using autofill increments the value from N5 through 6-10, which I don't want and my existing recorded macro pastes the value into more empty rows than I even want to bother counting.  🙂

Is there a line or two of code that would say - paste the copied value into Col. N for as many rows are used in Col. M?

Unfortunately this file is massive, even when I crop it down to almost nothing so the best I can do is provide a screen shot.

Hopefully it'll help with making sense of what I'm trying to do.

I would appreciate any help,

Thanks, Brenda

sp_AnswersTopicSeeAnswer See Answer
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1824
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
July 1, 2016 - 1:40 pm
sp_Permalink sp_Print

Hi Brenda,

You have no attachment, not even an image. Press the Start Upload button after you Add a file, only then the file will be uploaded.

I think you might have unnecessary formattings, this is one of the reasons why the size of a file is unnusually large. You can also paste a sample of your data into a new clean workbook, so we can see what you need.

Cheers,

Catalin

sp_AnswersTopicAnswer
Answers Post
Avatar
Brenda Delorme

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
June 16, 2015
sp_UserOfflineSmall Offline
3
July 1, 2016 - 3:05 pm
sp_Permalink sp_Print

Hi, Catalin

Thanks for the reply!  It seems like I have been here forever but I did manage to get an alternative -

Range("N5:N" & LastCell).Value = 1

As for the size of my file- thanks for the suggestion.  I thought I had indeed previously tried as you suggested, unsuccessfully, but I did it again and BOOM.  From 20,695kb down to 2546.

As always, MOTH Rocks!

Stay safe and well.

And thanks again, BrendaKiss 

Avatar
tbeards

New Member
Members
Level 0
Forum Posts: 1
Member Since:
June 27, 2016
sp_UserOfflineSmall Offline
4
July 7, 2016 - 2:25 am
sp_Permalink sp_Print

I see you found an alternative; however, I just wanted to post some code that I use all the time to fill a column based on contents of another column.

    Range("N5").Select
    Range("N5").Copy Destination:=Range("N5:N" & Cells(Rows.Count, "M").End(xlUp).Row)

Going further, I mostly use the code above to copy a formula down such as:

    Range("C2").Value = "=IF(ISNUMBER(A2),TEXT(A2,""000000""),A2)" 'formula I want to apply to column A to zero fill if it is a number
    Range("C2").Select
    Range("C2").Copy Destination:=Range("C2:C" & Cells(Rows.Count, "A").End(xlUp).Row) 'copy cell C2 down for as many rows are populated in column A
    Range("C:C").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False 'copy and paste the formulas as values
    Range("C:C").Select
    Selection.Copy
    Range("A1").Select
    ActiveSheet.Paste 'move the new values from column C to column A
    Range("A1").Value = "Level 1" 'rename the header to the original header

Avatar
Kliche

New Member
Members
Level 0
Forum Posts: 1
Member Since:
July 9, 2016
sp_UserOfflineSmall Offline
5
July 9, 2016 - 12:27 pm
sp_Permalink sp_Print

And tbeards solution will be more "elegant" if you avoid some "Select", that normally are not necessary. Example:

Range("N5").Select

Range("C2").Select

In this case, both ranges refer to Activesheet.

 

HTH.

K-Li-Ch

 

    

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Mark McCosker
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 215
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
jo moffitt
Michael Zandt
Ibraam Nasif
Gali Balmocena
Jocelyn Degran
Nurul Amalina
Sarah Mooney
Gopinath Gopalan
Nick Pape
Fakhar Zaman
Forum Stats:
Groups: 3
Forums: 24
Topics: 6347
Posts: 27751

 

Member Stats:
Guest Posters: 49
Members: 32305
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.