Error in finding the last used cell

zubin

New Member
Joined
Sep 15, 2019
Messages
47
Hi All....
I am having Three Ranges in a worksheet, "B4:B14", "E4:E14", "F4:F14"

All the cells in the range "F4:F14" has formulae,

The Values of these ranges have to be copied in the Columns "B", "D" and "E" respectively
ie Values of Range "B4:B14" has to be copied in the last available cell (Row) in column "B"
Values of Range "E4:E14" has to be copied in the last available cell (Row) in column "D"
Values of Range "F4:F14" has to be copied in the last available cell (Row) in column "E"

The below code i am using does the work well, It copies the first two ranges "B4:B14", "E4:E14" correctly everytime without any error,
but the Range "F4:F14" is where the problem comes.....most of the time it copies the values, but with a gap of a few cell (Rows) in between,
please note the cells in this range has formulae.

VBA Code:
Sheet1.Range("B4:B14").Copy
    Sheet1.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues
    Selection.Value = Selection.Value
    
    Sheet1.Range("E4:E14").Copy
    Sheet1.Range("D" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues
    Selection.Value = Selection.Value
    
    Sheet1.Range("F4:F14").Copy
    Sheet1.Range("E" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues
    Selection.Value = Selection.Value
        
      
    Application.CutCopyMode = False


I have tried various codes, but the error occurs

SCM Current-Dist-3ScreenCopy.xlsm
ABCDE
18411:47KFSTM650BBOX KFSTM65011995
18511:47LPS650BBOX LPS6501
18611:47LPM650BBOX LPM6501
18711:47LPM330BBOX LPM3301
18811:47KFS650BBOX KFS6502
18911:47KFM650BBOX KFM6501
19011:47KFS330BBOX KFS3301
191  
192  
193  
194  
195  1600
196  1460
197  1824
198  3876
199  1938
200  2234.4
201  
04-18-2021
Cell Formulas
RangeFormula
A184:A201A184=TIMESTAMP(B184)
C184:C201C184=IFERROR(VLOOKUP(B184,$M$1:$Q$6000,2,FALSE),"")
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Perhaps
VBA Code:
Sheet1.Range("E4:F14").Copy
Sheet1.Range("D" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues
Selection.Value = Selection.Value
    
' remove Sheet1.Range("F4:F14").Copy
' remove Sheet1.Range("E" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues
' remove Selection.Value = Selection.Value
 
Upvote 0
Sheet1.Range("E" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues
Try changing the above line of code to this...
VBA Code:
Sheet1.Range("E" & Sheet1.Columns("A").Find("*", , xlValues, , xlRows, xlPrevious).Row + 1).PasteSpecial xlValues
 
Upvote 0
Try changing the above line of code to this...
VBA Code:
[CODE=vba]Sheet1.Range("E" & Sheet1.Columns("E").Find("*", , xlValues, , xlRows, xlPrevious).Row + 1).PasteSpecial xlValues
[/CODE]
Should it not be...
Code:
Sheet1.Range("E" & Sheet1.Columns("E").Find("*", , xlValues, , xlRows, xlPrevious).Row + 1).PasteSpecial xlValues
 
Upvote 0
Should it not be...
Code:
Sheet1.Range("E" & Sheet1.Columns("E").Find("*", , xlValues, , xlRows, xlPrevious).Row + 1).PasteSpecial xlValues
So far the code is working good.....but it takes longer to execute...
Why was my previous code giving errors.
 
Upvote 0
Should it not be...
Code:
Sheet1.Range("E" & Sheet1.Columns("E").Find("*", , xlValues, , xlRows, xlPrevious).Row + 1).PasteSpecial xlValues
Yes, it should have been "E", not "A" (bad editing on my part). Your code did not work because your method see formulas as filled cells even when display "". I don't see a reason why my method should be slower than yours.
 
Upvote 0
Solution
Yes, it should have been "E", not "A" (bad editing on my part). Your code did not work because your method see formulas as filled cells even when display "". I don't see a reason why my method should be slower than yours.
Thanks a lot Rick.....
 
Upvote 0
In continuation of above code.....every time a range is copied can all the cells in the range be given a color depending on the value of the cell "F15"
Say If "F15" < 1000 Color of the copied range "Green"
If "F15" > 1000 Color of the copied range "Blue"
If "F15" > 10000 Color of the copied range "Red"
And I have a List box which displays this range..... the same color of the range should show up in the listbox, Is this Possible
and is this within the scope of this Tread

Or

Should i start a new tread
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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