copying data from 2 colums trough condition

comfil

New Member
Joined
Feb 13, 2018
Messages
2
hello ,i am having trouble making a small vbs sript to copy data in an excel file.
Sorry ,new at this.
I want to copy data from column B or C to column D(byscript) .The condition to chose between column B or C is that column A is 0,00 or 20,00
result should look like this:
[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 256"]
<tbody>[TR]
[TD="class: xl69, width: 64"][/TD]
[TD="class: xl65, width: 64"]0[/TD]
[TD="class: xl65, width: 64"]20[/TD]
[TD="class: xl67, width: 64"]bymacro[/TD]
[/TR]
[TR]
[TD="class: xl70"]0,00[/TD]
[TD="class: xl66"]7001[/TD]
[TD="class: xl66"]7010[/TD]
[TD="class: xl68"]7001[/TD]
[/TR]
[TR]
[TD="class: xl70"]0,00[/TD]
[TD="class: xl66"]7002[/TD]
[TD="class: xl66"]7011[/TD]
[TD="class: xl68"]7002[/TD]
[/TR]
[TR]
[TD="class: xl70"]20,00[/TD]
[TD="class: xl66"]7003[/TD]
[TD="class: xl66"]7012[/TD]
[TD="class: xl68"]7012[/TD]
[/TR]
[TR]
[TD="class: xl70"]20,00[/TD]
[TD="class: xl66"]7004[/TD]
[TD="class: xl66"]7013[/TD]
[TD="class: xl68"]7013[/TD]
[/TR]
[TR]
[TD="class: xl70"]0,00[/TD]
[TD="class: xl66"]7005[/TD]
[TD="class: xl66"]7014[/TD]
[TD="class: xl68"]7005[/TD]
[/TR]
[TR]
[TD="class: xl70"]20,00[/TD]
[TD="class: xl66"]7006[/TD]
[TD="class: xl66"]7015[/TD]
[TD="class: xl68"]7015[/TD]
[/TR]
[TR]
[TD="class: xl70"]0,00[/TD]
[TD="class: xl66"]7007[/TD]
[TD="class: xl66"]7016[/TD]
[TD="class: xl68"]7007[/TD]
[/TR]
[TR]
[TD="class: xl70"]20,00[/TD]
[TD="class: xl66"]7008[/TD]
[TD="class: xl66"]7017[/TD]
[TD="class: xl68"]7017[/TD]
[/TR]
[TR]
[TD="class: xl70"]20,00[/TD]
[TD="class: xl66"]7009[/TD]
[TD="class: xl66"]7018[/TD]
[TD="class: xl68"]7018[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

I have this ,sofar: (i have no errros, but its not copying anything)
Code:
Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim myFile As String
    Dim LastRow As Long
    Dim rng As Range
    myFile = Application.GetOpenFilename
    Workbooks.Open Filename:=myFile
    LastRow = ActiveWorkbook.Sheets("Blad1").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each rng In Range("A2:A" & LastRow)
        If rng = 20 Then
            rng.Offset(0, 3) = rng.Offset(0, 2)
        Else
            rng.Offset(0, 3) = rng.Offset(0, 1)
        End If
    Next rng
    ActiveWorkbook.Save
    Application.ScreenUpdating = True
End Sub
thx alot for any help !
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Dim c As Range, rng
Dim lr As Long
lr = Range("a" & Rows.Count).End(xlUp).Row
Set rng = Range("a1:a" & lr)
For Each c In rng
If c.Value = 20 Then
c.Offset(0, 3) = c.Offset(0, 2)
End If
If c.Value = 0 Then
c.Offset(0, 3) = c.Offset(0, 1)
End If
Next c
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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