Macro not working if assigned to a button or even on its own

subash86

New Member
Joined
May 18, 2018
Messages
2
Hi

I have written a VB macro to transfer contents from one excel to another. However, if I run the macro (either from VB window or assign it to a button) it returns only one value (NO ERROR) but if I debug and have both the related excel files and go to each of the excel files step by step, I achieve the desired result.
I am a new user of macro, but I can see my logic in the code is right and since it does not return any error, I feel the error is with respect to opening of the corresponding excel files for that purpose.
I can share the code, if anyone can look into it and give me a suggestion.

Thanks
Suba
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi

I have written a VB macro to transfer contents from one excel to another. However, if I run the macro (either from VB window or assign it to a button) it returns only one value (NO ERROR) but if I debug and have both the related excel files and go to each of the excel files step by step, I achieve the desired result.
I am a new user of macro, but I can see my logic in the code is right and since it does not return any error, I feel the error is with respect to opening of the corresponding excel files for that purpose.
I can share the code, if anyone can look into it and give me a suggestion.

Thanks
Suba
If you post your code and an explanation of what it is intended to do, you will greatly improve your chances of getting some help.
 
Upvote 0
you need to post the complete macro for us to review.

Hi Jim.
Please find my code below. I am trying to check three conditions and copy the corresponding names from one excel to another excel.

==========================================================
Code:
Sub cond_copy()
'These are location indicators for destination workbook
y1 = 4
 y2 = 4
 y3 = 4
 
For x = 4 To 18
  Workbooks("Sample_Doc.xlsm").Activate
  Sheets("Sheet1").Select
 
  If IsEmpty(Cells(x, 5).Value) = True Then
  y1 = y1
  y2 = y2
  y3 = y3
  ElseIf Cells(x, 5) = "E" And (Cells(x, 2) = "HIGH" Or Cells(x, 2) = "GR7") Then
  If Cells(x, 4) = "Y" Then
  temp = Split(Cells(x, 1).Value, " ")(0)
  FirstName = temp & "*"
  Else
  FirstName = Split(Cells(x, 1).Value, " ")(0)
  End If
 
Workbooks("Sample_Allocation.xlsm").Sheets("AS1").Activate
  Cells(y2, 7) = FirstName
  y2 = y2 + 1
 ElseIf Cells(x, 5) = "M" And (Cells(x, 2) = "HIGH" Or Cells(x, 2) = "GR7") Then
  If Cells(x, 4) = "Y" Then
  temp = Split(Cells(x, 1).Value, " ")(0)
  FirstName = temp & "*"
  Else
  FirstName = Split(Cells(x, 1).Value, " ")(0)
  End If
 
Workbooks("Sample_Allocation.xlsm").Sheets("AS1").Activate
  Cells(y1, 2) = FirstName
  y1 = y1 + 1
  ElseIf Cells(x, 5) = "N" And (Cells(x, 2) = "HIGH" Or Cells(x, 2) = "GR7") Then
  If Cells(x, 4) = "Y" Then
  temp = Split(Cells(x, 1).Value, " ")(0)
  FirstName = temp & "*"
  Else
  FirstName = Split(Cells(x, 1).Value, " ")(0)
  End If
  
  Workbooks("Sample_Allocation.xlsm").Sheets("AS1").Activate
  Cells(y3, 12) = FirstName
  y3 = y3 + 1
  ElseIf Cells(x, 5) = "O" Then
  y1 = y1
  y2 = y2
  y3 = y3
  End If
  Next x
End Sub
======================================

Thanks
Suba
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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