• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Set Variable as If condition

AAP

Member
Hello Friends, need help to set a variable with if condition.

The below code I need to copy with every worksheet and I have more than 100 sheets in a workbook, so I think to make this below condition as variable. So that instead of copying and pasting whole code I can write just a word called "Checking". Thanks

[If Range("A2").Value <> "" Then
If Range("A3").Value = "" Then
Range("A2:G2").Select
Selection.Copy
Else
Range("A2:G2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
End If
Workbooks("Siba Macro.xlsm").Worksheets("Data").Activate
Range("A2").Select
Selection.End(xlDown).Select
Selection.Offset(1, 0).Select
Selection.PasteSpecial xlPasteValues
End If]
 
Hi Somendra, Raw Data Dk is the sample file from where I want to copy the data from all sheets and paste it into SIBA file. Thanks
 

Attachments

  • Raw Data-DK-ComCity.xlsx
    52 KB · Views: 3
  • SIBA.xlsx
    11.9 KB · Views: 1
Hi Aap,

Can you explain your conditions of copying in words, i.e. why you are checking A2 and A3 for not blanks? As there is data in all sheets in these cells.

Regards,
 
Hi Somendra, Its a web query and sometimes due to problems sometimes it does not fill A2 which either means no data available or error. Sometimes A2 contains data and A3 is blank- not because of error but sometimes there is no data for that point. If I start copy from cell A2 and hold ctrl + downkey it will take me to the end of the excel sheet instead. Therefore I use these two checks.
 
@AAP

See this file. Open both the SIBA & this file open and run the code from DK file making keeping it active workbook.

2 things which I had not done: Serial No. on SIBA file is as per DK file so it is not arranged.

I had not included both your A2 and A3 condition.

Regards,
 

Attachments

  • Raw Data-DK-ComCity.xlsm
    63.6 KB · Views: 1
Many thanks Somendra, this is working good. Can it be possible to include A2 and A3 condition? Otherwise I need to go manually in every sheet and check if there is error or no value... Again thanks for you kind help.
 
Back
Top