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!
 
What's in the relevant cells when you get that error? I tested the code before posting it, with I1 = 11.

Please see pic.
relevant.jpg
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
What's the value of i1 when you get a type mismatch?
when i1 are smaller then 4
just corrected code and i'm testing it, do you work on TestVBA?

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


Sheet2.Cells(i1, 14).Value = Sheet1.Cells(Sheet2.Cells(i1, 1).Value, 2).Value


    i1 = i1 + 1


Loop
 
Upvote 0
Yes I used your workbook.

Why are you using Range("A4:A" & LR).SpecialCells(xlCellTypeConstants).Count +4 rather than just LR?
 
Upvote 0
when i'm using LR it dos't read last row so i need to use LR+1
But anyway it's amazing you shortened my code 4 x times and it's still working even better
 
Upvote 0

Forum statistics

Threads
1,215,472
Messages
6,125,005
Members
449,203
Latest member
Daymo66

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