Values between sheets

cerins4ever

New Member
Joined
Jun 5, 2014
Messages
35
Hi guys, i have one problem with data transfer between sheets, hope someone professional will give me answer.
I have MsgBox code which is not working, where is problem?
Is it problem with that in the code are line .End(xlUp).SpecialCells(xlCellTypeVisible) or what?

Code:
Private Sub CommandButton1_Click()

Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row

Dim i1 As Integer
i1 = 1
Do While i1 < Sheet2.Range("A4:A" & LR).SpecialCells(xlCellTypeConstants).Count + 1


MsgBox Sheet1.Range("A4", Cells(Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(Sheet2.Range("A4", Cells(Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(i1, 1).Value - 3, 2).Value


    i1 = i1 + 1
Loop
End Sub

Thanks a lot!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
That's because End(xlUp) bypasses hidden rows.

Yes it's true
I'm using following formula to find last row even it's hided

Code:
 Dim ws As Worksheet
Dim temp As Worksheet
    Dim lastrow As Long
    Set ws = Sheets("Nepieciešams")
    ws.Copy Before:=Sheets(1)
    Set temp = ActiveSheet
    If temp.AutoFilterMode Then temp.AutoFilterMode = False
    temp.Columns("A:A").EntireRow.Hidden = False
    lastrow = temp.Range("A" & temp.Rows.Count).End(xlUp).Offset(1, 0).Row
    Application.DisplayAlerts = False
    temp.Delete
    Application.DisplayAlerts = True
Is't shortest way? if it's not Maybe you can recommend shorter way
 
Upvote 0
It's tricky with AutoFilter. In your particular case you can use:

Code:
lastrow = Sheets("Nepieciešams").Range("A1").CurrentRegion.Rows.Count
 
Upvote 0
It's tricky with AutoFilter. In your particular case you can use:

Rich (BB code):
lastrow = Sheets("Nepieciešams").Range("A1").CurrentRegion.Rows.Count


yup it's tricky and on web there are less answers on this question, looks like code

Code:
[COLOR=#333333]Sheets("Nepieciešams").Range("A1").CurrentRegion.Rows.Count[/COLOR]

will no be suitable for me, because also these ID codes i will hide.

Thanks a lot any way for help.
you are professional!
My code now are 4 x times shorter and lighter also!
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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