Taking Macro Recorder and Creating VBA Code

beginvbaanalyst

Board Regular
Joined
Jan 28, 2020
Messages
139
Office Version
  1. 365
Platform
  1. Windows
Hello Everyone,

This is my first post so I hope I don't put to much information in here.
I recently decided I wanted to make my work automated and since I use excel daily I came across VBA.
Recently started using Macro Recorder but don't know much about VBA. I've been watching videos daily for the past week.
Currently I'm having an issue when I run my macro it doesn't always complete the set of data provided within each column.
Is there a way to instead of running a selected range, have the macro run until the end of the set of data within each column?

Provided Below is the Macro Recorder Code

Range("I1").Select 'Selection of Column I, Row One ("I1")
ActiveCell.FormulaR1C1 = "ARTICLE" 'Naming Selection "I1", ("Article")
Range("J1").Select 'Selection of Column J, Row One ("J1")
ActiveCell.FormulaR1C1 = "VENDOR" 'Naming Selection "J1",("Vendor")
Range("K1").Select 'Selection of Column K, Row One ("K1")
ActiveCell.FormulaR1C1 = "REGULAR" 'Naming Selection "K1"), ("Regular")
Range("L1").Select 'Selection of Column L, Row one ("L1")
ActiveCell.FormulaR1C1 = "BURRIS" 'Naming Selection ("L1"), ("Burris")
Range("M1").Select 'Selection of Column M, ROw One ("M1")
ActiveCell.FormulaR1C1 = "B REG" 'Naming Selection ("M1"), ("B REG")
Range("I2").Select 'Selection of Column I, Row Two ("I2")
ActiveCell.FormulaR1C1 = "" 'Don't know what this does yet
Range("B2").Select 'Selection of Column B, Row 2 ("B2")
Range(Selection, Selection.End(xlDown)).Select 'Selected Range Until Last Row Entry
Selection.Copy 'Copy Selected Range
Range("I2").Select 'Selected Paste Area ("I2")
ActiveSheet.Paste 'Selected ("I2")
Application.CutCopyMode = False 'Pasted Selected Range into Column I, Row Two ("I2")
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
It looks like you can do what you want with the following:
VBA Code:
Sub test()
    Range("I1:M1") = Array("ARTICLE", "VENDOR", "REGULAR", "BURRIS", "B REG")
    Range("B2", Range("B" & Rows.Count).End(xlUp)).Copy Range("I2")
End Sub
You generally don't have to select a cell in order to copy it or paste to it. Recorded macros are a good start to learning VBA but you almost always have to modify them to get them to adjust automatically to changes in your data.
 
Upvote 0
It looks like you can do what you want with the following:
VBA Code:
Sub test()
    Range("I1:M1") = Array("ARTICLE", "VENDOR", "REGULAR", "BURRIS", "B REG")
    Range("B2", Range("B" & Rows.Count).End(xlUp)).Copy Range("I2")
End Sub
You generally don't have to select a cell in order to copy it or paste to it. Recorded macros are a good start to learning VBA but you almost always have to modify them to get them to adjust automatically to changes in your data.

I've been going through the macro code line by line to understand what each section does and adding comments.
I assumed there would be a much easier way to get the set of data I wanted with less code.
I appreciate your help!
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,230
Messages
6,123,752
Members
449,118
Latest member
kingjet

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top