copying data from 2 colums trough condition

Status
Not open for further replies.

comfil

New Member
Joined
Feb 13, 2018
Messages
2
hello ,i am having trouble making a small vbs sript to copy data in an exfel 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 or 20.
Results should look like this:
[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 256"]
<colgroup><col width="64" style="width:48pt"> <col width="64" span="2" style="width:48pt"> <col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl67, width: 64"] [/TD]
[TD="class: xl65, width: 64"]0[/TD]
[TD="class: xl65, width: 64"]20[/TD]
[TD="class: xl69, width: 64"]byscript[/TD]
[/TR]
[TR]
[TD="class: xl68"]0,00[/TD]
[TD="class: xl66"]7001[/TD]
[TD="class: xl66"]7010[/TD]
[TD="class: xl69"]7001[/TD]
[/TR]
[TR]
[TD="class: xl68"]20,00[/TD]
[TD="class: xl66"]7002[/TD]
[TD="class: xl66"]7011[/TD]
[TD="class: xl69"]7011[/TD]
[/TR]
[TR]
[TD="class: xl68"]20,00[/TD]
[TD="class: xl66"]7003[/TD]
[TD="class: xl66"]7012[/TD]
[TD="class: xl69"]7012[/TD]
[/TR]
[TR]
[TD="class: xl68"]20,00[/TD]
[TD="class: xl66"]7004[/TD]
[TD="class: xl66"]7013[/TD]
[TD="class: xl69"]7013[/TD]
[/TR]
[TR]
[TD="class: xl68"]0,00[/TD]
[TD="class: xl66"]7005[/TD]
[TD="class: xl66"]7014[/TD]
[TD="class: xl69"]7005[/TD]
[/TR]
[TR]
[TD="class: xl68"]0,00[/TD]
[TD="class: xl66"]7006[/TD]
[TD="class: xl66"]7015[/TD]
[TD="class: xl69"]7006[/TD]
[/TR]
[TR]
[TD="class: xl68"]20,00[/TD]
[TD="class: xl66"]7007[/TD]
[TD="class: xl66"]7016[/TD]
[TD="class: xl69"]7016[/TD]
[/TR]
[TR]
[TD="class: xl68"]20,00[/TD]
[TD="class: xl66"]7008[/TD]
[TD="class: xl66"]7017[/TD]
[TD="class: xl69"]7017[/TD]
[/TR]
[TR]
[TD="class: xl68"]0,00[/TD]
[TD="class: xl66"]7009[/TD]
[TD="class: xl66"]7018[/TD]
[TD="class: xl69"]7009[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

I have this ,sofar: (i have no errors but its not copying anything)
Code:
Sub CommandButton1_Click()
    Dim myFile As String
    Dim sht As Worksheet
    Dim LastRow As Long
    Dim rng As Range
    myFile = Application.GetOpenFilename
    Workbooks.Open Filename:=myFile
    Set sht = ActiveSheet
    LastRow = sht.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
    For Each rng In Range("A2:A" & LastRow)
        If rng = "20,00" Then
            rng.Offset(0, 3) = rng.Offset(0, 2)
        Else
            rng.Offset(0, 3) = rng.Offset(0, 1)
        End If
    Next rng
    ActiveWorkbook.Save
End Sub

thanks alot for any help!!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I copied your data and VBA into a blank spreadsheet, commented out the Openening and saving of the files, ran it and it worked fine, filled in column D based on values in column A.
 
Upvote 0
Duplicate https://www.mrexcel.com/forum/excel-questions/1043215-copying-data-2-colums-trough-condition.html

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).

If you do not receive a response, you can "bump" it by replying to it again, though we advise you to wait 24 hours before doing and not to bump a thread more than once a day.

Note that sometimes posts from new users require Moderator approval before you can see them on the public forums. When this happens, you should see a message to that effect when you try to post it.
Please be patient and do not attempt to post the question again.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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