VBA:Find last value in column

Robert Mika

MrExcel MVP
Joined
Jun 29, 2009
Messages
7,256
What I'm trying to do is to find last value in column from which data are deliverd from formula.
Example
Column A has 20 rows with simple formula
=if(b1="","",b1)
....
...
....
=if(b20="","",b20)

The number of non blank cell can be difftrent each time and I woud like to copy only those which are non blank(by non-blank means they have value)
So far I got here:

Code:
Range("a2").Select
    
    Range("b2", Range("b2").End(xlDown)).Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=True, Transpose:=False
but this copy all 20 rows not the one with values.

This bit:
Code:
SkipBlanks _
        :=True

does not work for what I'm trying to accomplish.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi,

Best way to find last row of data is to use xlUp not xlDown...

Code:
Range("A" & rows.count).End(xlup).Row

If your using PasteSpecial Values you will only bring across the values, blanks will come over as blanks, to remove the blanks from the destination list you could use the Sort function.

Hope this helps.
 
Upvote 0
Hi Mike,
Sorry for my ignorance.
What you have suggested did not work.
I assume I have entered that into wrong place replacing this part:

Code:
Range("e2", Range("e2").End(xlDown)).Copy
with your suggestion


My code so far look like this:
Code:
Sub GoToSingleColumn()
    
    Range("a2").Select
    
    Range("e2", Range("e2").End(xlDown)).Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    
    ActiveCell.End(xlDown).Offset(1, 0).Select
    
    
    Range("f2", Range("f2").End(xlDown)).Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    ActiveCell.End(xlDown).Offset(1, 0).Select
    
    Range("g2", Range("g2").End(xlDown)).Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    ActiveCell.End(xlDown).Offset(1, 0).Select
    Range("a2").CurrentRegion.RemoveDuplicates Columns:=Array(1), _
        Header:=xlNo
        Range("a2").Select
    
    
    
End Sub

Copying three columns into one and then removing duplicates

But it still include one empty cell inbeetwee rows.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,183
Members
452,893
Latest member
denay

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