Macros

D

Debbie

I'm new at running macros and I currently use the "record macro" button. I
need to run a macro that recognizes "only populated data" in the columns so I
can copy an paste it into another worksheet. The number of rows with data in
them will change daily and I need the macro to compensate.

You can do this with a filter and only filter "non blanks" but the macro
does not adjust accordingly the next day if it record it.

Any assistance would be great!
 
M

Mike H

Debbie,

Without seeing your code it's difficult but if your copying data then
somewhere in your recorded macro you will have a line simliar to

Range("A1:A10").Select
Selection.Copy

Now this as you have discovered is a fixed range that you need to make
dynamic so first find the last row with

lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row

Then create the range and copy with this

Range("A1:A" & lastrow).Copy

Note unlike a recorded macro i did it without selecting anything
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
D

Debbie

When I type in lastrow = Cells(Cells.Rows.Count, "A").End(x1Up).Row the macro
gives me an error staying last row is empty. Below is an example of the
recorded macro I was using.

Range("V7").Select
Selection.AutoFilter Field:=20, Criteria1:="<>"
Range("V7:AI7").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("V7:AS350").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Combined Upload File").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

I originally used a filter to select only nonblank rows but found that would
not work. My next options was to go the other spectrum and copy all of the
rows (whether there was data or not). The example above shows this scenario.


What I would prefer to do is only copy the rows that have data so the macro
recognizes each day those rows that have data within column "V". The data
could begin to populate in row 7 but row 7 may or may not be populated
depending on if the formula that feeds into V7 provides any results. Column
V - AI results are determined by a formula
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top