Copy rows without triggering a macro VBA









up vote
1
down vote

favorite












There's a few questions relating to this subject but I'm struggling a bit.



I have a MASTER sheet that stores various information. I use Column B to hide/unhide other columns. So for each different value entered in Column B, it will display the appropriate Columns. e.g. If X is entered in Column B, Col C:F will be displayed and Col G:I will be hidden.



This works fine but I want to automatically copy identical values from this sheet to separate sheets. e.g. grab all X's in MASTER and copy to a separate sheet that contains only X's.



I can do this but only through the use of a macro that needs to be triggered. This isn't very efficient if I need to copy numerous rows. Especially if you've only updated 1 row but need to copy everything.



I want to automatically auto-copy as soon as a value is entered. Without needing to trigger a macro



This is the script the hides/unhides specific columns in the MASTER sheet:



Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False
Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:
Application.EnableEvents = True
End Sub


As I can't add a separate Worksheet_Change to this script to auto-copy across I'm a bit confused in how to do this



I'm currently using the script below. This copies the appropriate rows to the respective sheet. But it only works when triggered. I'm hoping to automatically copy the row once filled in.



@Gexas, how is this?



Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False
Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If
safe_exit:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False

.AutoFilter field:=1, Criteria1:="Change of Numbers"

.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False

.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With
End Sub









share|improve this question























  • So call it from the Worksheet_Change event? I feel like I'm missing something here...
    – Comintern
    Nov 9 at 5:37










  • Huh? You've completely lost me. Why would FilterAndCopy() need to be in the MASTER sheet - it's implicitly public.
    – Comintern
    Nov 9 at 5:49










  • I'm obviously a bit lost here. I don't understand what needs to go into what Worksheet.
    – JPA0888
    Nov 9 at 5:51










  • What am I calling from the Worksheet_Change event?
    – JPA0888
    Nov 9 at 5:52











  • FilterAndCopy() as I understand the question.
    – Comintern
    Nov 9 at 5:54














up vote
1
down vote

favorite












There's a few questions relating to this subject but I'm struggling a bit.



I have a MASTER sheet that stores various information. I use Column B to hide/unhide other columns. So for each different value entered in Column B, it will display the appropriate Columns. e.g. If X is entered in Column B, Col C:F will be displayed and Col G:I will be hidden.



This works fine but I want to automatically copy identical values from this sheet to separate sheets. e.g. grab all X's in MASTER and copy to a separate sheet that contains only X's.



I can do this but only through the use of a macro that needs to be triggered. This isn't very efficient if I need to copy numerous rows. Especially if you've only updated 1 row but need to copy everything.



I want to automatically auto-copy as soon as a value is entered. Without needing to trigger a macro



This is the script the hides/unhides specific columns in the MASTER sheet:



Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False
Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:
Application.EnableEvents = True
End Sub


As I can't add a separate Worksheet_Change to this script to auto-copy across I'm a bit confused in how to do this



I'm currently using the script below. This copies the appropriate rows to the respective sheet. But it only works when triggered. I'm hoping to automatically copy the row once filled in.



@Gexas, how is this?



Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False
Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If
safe_exit:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False

.AutoFilter field:=1, Criteria1:="Change of Numbers"

.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False

.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With
End Sub









share|improve this question























  • So call it from the Worksheet_Change event? I feel like I'm missing something here...
    – Comintern
    Nov 9 at 5:37










  • Huh? You've completely lost me. Why would FilterAndCopy() need to be in the MASTER sheet - it's implicitly public.
    – Comintern
    Nov 9 at 5:49










  • I'm obviously a bit lost here. I don't understand what needs to go into what Worksheet.
    – JPA0888
    Nov 9 at 5:51










  • What am I calling from the Worksheet_Change event?
    – JPA0888
    Nov 9 at 5:52











  • FilterAndCopy() as I understand the question.
    – Comintern
    Nov 9 at 5:54












up vote
1
down vote

favorite









up vote
1
down vote

favorite











There's a few questions relating to this subject but I'm struggling a bit.



I have a MASTER sheet that stores various information. I use Column B to hide/unhide other columns. So for each different value entered in Column B, it will display the appropriate Columns. e.g. If X is entered in Column B, Col C:F will be displayed and Col G:I will be hidden.



This works fine but I want to automatically copy identical values from this sheet to separate sheets. e.g. grab all X's in MASTER and copy to a separate sheet that contains only X's.



I can do this but only through the use of a macro that needs to be triggered. This isn't very efficient if I need to copy numerous rows. Especially if you've only updated 1 row but need to copy everything.



I want to automatically auto-copy as soon as a value is entered. Without needing to trigger a macro



This is the script the hides/unhides specific columns in the MASTER sheet:



Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False
Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:
Application.EnableEvents = True
End Sub


As I can't add a separate Worksheet_Change to this script to auto-copy across I'm a bit confused in how to do this



I'm currently using the script below. This copies the appropriate rows to the respective sheet. But it only works when triggered. I'm hoping to automatically copy the row once filled in.



@Gexas, how is this?



Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False
Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If
safe_exit:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False

.AutoFilter field:=1, Criteria1:="Change of Numbers"

.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False

.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With
End Sub









share|improve this question















There's a few questions relating to this subject but I'm struggling a bit.



I have a MASTER sheet that stores various information. I use Column B to hide/unhide other columns. So for each different value entered in Column B, it will display the appropriate Columns. e.g. If X is entered in Column B, Col C:F will be displayed and Col G:I will be hidden.



This works fine but I want to automatically copy identical values from this sheet to separate sheets. e.g. grab all X's in MASTER and copy to a separate sheet that contains only X's.



I can do this but only through the use of a macro that needs to be triggered. This isn't very efficient if I need to copy numerous rows. Especially if you've only updated 1 row but need to copy everything.



I want to automatically auto-copy as soon as a value is entered. Without needing to trigger a macro



This is the script the hides/unhides specific columns in the MASTER sheet:



Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False
Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:
Application.EnableEvents = True
End Sub


As I can't add a separate Worksheet_Change to this script to auto-copy across I'm a bit confused in how to do this



I'm currently using the script below. This copies the appropriate rows to the respective sheet. But it only works when triggered. I'm hoping to automatically copy the row once filled in.



@Gexas, how is this?



Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False
Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If
safe_exit:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False

.AutoFilter field:=1, Criteria1:="Change of Numbers"

.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False

.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With
End Sub






excel vba automation copy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 6:33

























asked Nov 9 at 5:15









JPA0888

659




659











  • So call it from the Worksheet_Change event? I feel like I'm missing something here...
    – Comintern
    Nov 9 at 5:37










  • Huh? You've completely lost me. Why would FilterAndCopy() need to be in the MASTER sheet - it's implicitly public.
    – Comintern
    Nov 9 at 5:49










  • I'm obviously a bit lost here. I don't understand what needs to go into what Worksheet.
    – JPA0888
    Nov 9 at 5:51










  • What am I calling from the Worksheet_Change event?
    – JPA0888
    Nov 9 at 5:52











  • FilterAndCopy() as I understand the question.
    – Comintern
    Nov 9 at 5:54
















  • So call it from the Worksheet_Change event? I feel like I'm missing something here...
    – Comintern
    Nov 9 at 5:37










  • Huh? You've completely lost me. Why would FilterAndCopy() need to be in the MASTER sheet - it's implicitly public.
    – Comintern
    Nov 9 at 5:49










  • I'm obviously a bit lost here. I don't understand what needs to go into what Worksheet.
    – JPA0888
    Nov 9 at 5:51










  • What am I calling from the Worksheet_Change event?
    – JPA0888
    Nov 9 at 5:52











  • FilterAndCopy() as I understand the question.
    – Comintern
    Nov 9 at 5:54















So call it from the Worksheet_Change event? I feel like I'm missing something here...
– Comintern
Nov 9 at 5:37




So call it from the Worksheet_Change event? I feel like I'm missing something here...
– Comintern
Nov 9 at 5:37












Huh? You've completely lost me. Why would FilterAndCopy() need to be in the MASTER sheet - it's implicitly public.
– Comintern
Nov 9 at 5:49




Huh? You've completely lost me. Why would FilterAndCopy() need to be in the MASTER sheet - it's implicitly public.
– Comintern
Nov 9 at 5:49












I'm obviously a bit lost here. I don't understand what needs to go into what Worksheet.
– JPA0888
Nov 9 at 5:51




I'm obviously a bit lost here. I don't understand what needs to go into what Worksheet.
– JPA0888
Nov 9 at 5:51












What am I calling from the Worksheet_Change event?
– JPA0888
Nov 9 at 5:52





What am I calling from the Worksheet_Change event?
– JPA0888
Nov 9 at 5:52













FilterAndCopy() as I understand the question.
– Comintern
Nov 9 at 5:54




FilterAndCopy() as I understand the question.
– Comintern
Nov 9 at 5:54












2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










Filter and Copy



If you move the 'Sub' into the sheet code (Master), you can lose the 'sht1' in it like you did in the 'Private Sub', if not just add the line FilterAndCopy appropriately into the 'Private Sub'.



Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo safe_exit

' Something has changed in Column "B"
If Not Intersect(Target, Range("B:B")) Is Nothing Then

Application.EnableEvents = False

' *******************
FilterAndCopy ' *
' *******************

Dim t As Range

For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:

Application.EnableEvents = True

End Sub


'****************
Sub FilterAndCopy()

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False
.AutoFilter field:=1, Criteria1:="Change of Numbers"
.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False
.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With

End Sub
'****************





share|improve this answer






















  • But FilterAndCopy() still won't be triggered automatically, or I am wrong?
    – Gexas
    Nov 9 at 6:40

















up vote
1
down vote













Worksheet_Change event can have both of your functions inside. Since code is read from first to last line, with with order VBA will copy content from your second code and later hides columns. Code below should work, assuming everything else is good with. Note that I can not test it and did not check for other errors. Just changed order.



Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False

.AutoFilter field:=1, Criteria1:="Change of Numbers"

.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False

.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With

Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:
Application.EnableEvents = True
End Sub





share|improve this answer






















  • Nope, every time there is a change anywhere on the worksheet, sheet CON is being changed. No need to do this unless a value in a cell in the B column has changed to "Change of Numbers".
    – VBasic2008
    Nov 9 at 7:05










  • Oh I see what you talking about now, I'll change my answer to correct order then.
    – Gexas
    Nov 9 at 7:39










  • That's nice. Now I want to manually trigger FilterAndCopy (run macro).
    – VBasic2008
    Nov 9 at 7:52










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53220237%2fcopy-rows-without-triggering-a-macro-vba%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










Filter and Copy



If you move the 'Sub' into the sheet code (Master), you can lose the 'sht1' in it like you did in the 'Private Sub', if not just add the line FilterAndCopy appropriately into the 'Private Sub'.



Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo safe_exit

' Something has changed in Column "B"
If Not Intersect(Target, Range("B:B")) Is Nothing Then

Application.EnableEvents = False

' *******************
FilterAndCopy ' *
' *******************

Dim t As Range

For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:

Application.EnableEvents = True

End Sub


'****************
Sub FilterAndCopy()

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False
.AutoFilter field:=1, Criteria1:="Change of Numbers"
.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False
.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With

End Sub
'****************





share|improve this answer






















  • But FilterAndCopy() still won't be triggered automatically, or I am wrong?
    – Gexas
    Nov 9 at 6:40














up vote
2
down vote



accepted










Filter and Copy



If you move the 'Sub' into the sheet code (Master), you can lose the 'sht1' in it like you did in the 'Private Sub', if not just add the line FilterAndCopy appropriately into the 'Private Sub'.



Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo safe_exit

' Something has changed in Column "B"
If Not Intersect(Target, Range("B:B")) Is Nothing Then

Application.EnableEvents = False

' *******************
FilterAndCopy ' *
' *******************

Dim t As Range

For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:

Application.EnableEvents = True

End Sub


'****************
Sub FilterAndCopy()

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False
.AutoFilter field:=1, Criteria1:="Change of Numbers"
.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False
.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With

End Sub
'****************





share|improve this answer






















  • But FilterAndCopy() still won't be triggered automatically, or I am wrong?
    – Gexas
    Nov 9 at 6:40












up vote
2
down vote



accepted







up vote
2
down vote



accepted






Filter and Copy



If you move the 'Sub' into the sheet code (Master), you can lose the 'sht1' in it like you did in the 'Private Sub', if not just add the line FilterAndCopy appropriately into the 'Private Sub'.



Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo safe_exit

' Something has changed in Column "B"
If Not Intersect(Target, Range("B:B")) Is Nothing Then

Application.EnableEvents = False

' *******************
FilterAndCopy ' *
' *******************

Dim t As Range

For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:

Application.EnableEvents = True

End Sub


'****************
Sub FilterAndCopy()

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False
.AutoFilter field:=1, Criteria1:="Change of Numbers"
.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False
.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With

End Sub
'****************





share|improve this answer














Filter and Copy



If you move the 'Sub' into the sheet code (Master), you can lose the 'sht1' in it like you did in the 'Private Sub', if not just add the line FilterAndCopy appropriately into the 'Private Sub'.



Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo safe_exit

' Something has changed in Column "B"
If Not Intersect(Target, Range("B:B")) Is Nothing Then

Application.EnableEvents = False

' *******************
FilterAndCopy ' *
' *******************

Dim t As Range

For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:

Application.EnableEvents = True

End Sub


'****************
Sub FilterAndCopy()

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False
.AutoFilter field:=1, Criteria1:="Change of Numbers"
.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False
.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With

End Sub
'****************






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 25 at 10:00

























answered Nov 9 at 6:32









VBasic2008

679213




679213











  • But FilterAndCopy() still won't be triggered automatically, or I am wrong?
    – Gexas
    Nov 9 at 6:40
















  • But FilterAndCopy() still won't be triggered automatically, or I am wrong?
    – Gexas
    Nov 9 at 6:40















But FilterAndCopy() still won't be triggered automatically, or I am wrong?
– Gexas
Nov 9 at 6:40




But FilterAndCopy() still won't be triggered automatically, or I am wrong?
– Gexas
Nov 9 at 6:40












up vote
1
down vote













Worksheet_Change event can have both of your functions inside. Since code is read from first to last line, with with order VBA will copy content from your second code and later hides columns. Code below should work, assuming everything else is good with. Note that I can not test it and did not check for other errors. Just changed order.



Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False

.AutoFilter field:=1, Criteria1:="Change of Numbers"

.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False

.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With

Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:
Application.EnableEvents = True
End Sub





share|improve this answer






















  • Nope, every time there is a change anywhere on the worksheet, sheet CON is being changed. No need to do this unless a value in a cell in the B column has changed to "Change of Numbers".
    – VBasic2008
    Nov 9 at 7:05










  • Oh I see what you talking about now, I'll change my answer to correct order then.
    – Gexas
    Nov 9 at 7:39










  • That's nice. Now I want to manually trigger FilterAndCopy (run macro).
    – VBasic2008
    Nov 9 at 7:52














up vote
1
down vote













Worksheet_Change event can have both of your functions inside. Since code is read from first to last line, with with order VBA will copy content from your second code and later hides columns. Code below should work, assuming everything else is good with. Note that I can not test it and did not check for other errors. Just changed order.



Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False

.AutoFilter field:=1, Criteria1:="Change of Numbers"

.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False

.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With

Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:
Application.EnableEvents = True
End Sub





share|improve this answer






















  • Nope, every time there is a change anywhere on the worksheet, sheet CON is being changed. No need to do this unless a value in a cell in the B column has changed to "Change of Numbers".
    – VBasic2008
    Nov 9 at 7:05










  • Oh I see what you talking about now, I'll change my answer to correct order then.
    – Gexas
    Nov 9 at 7:39










  • That's nice. Now I want to manually trigger FilterAndCopy (run macro).
    – VBasic2008
    Nov 9 at 7:52












up vote
1
down vote










up vote
1
down vote









Worksheet_Change event can have both of your functions inside. Since code is read from first to last line, with with order VBA will copy content from your second code and later hides columns. Code below should work, assuming everything else is good with. Note that I can not test it and did not check for other errors. Just changed order.



Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False

.AutoFilter field:=1, Criteria1:="Change of Numbers"

.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False

.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With

Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:
Application.EnableEvents = True
End Sub





share|improve this answer














Worksheet_Change event can have both of your functions inside. Since code is read from first to last line, with with order VBA will copy content from your second code and later hides columns. Code below should work, assuming everything else is good with. Note that I can not test it and did not check for other errors. Just changed order.



Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets("MASTER")
Set sht2 = Worksheets("CON")

sht2.UsedRange.ClearContents

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error GoTo safe_exit
Application.EnableEvents = False

With Intersect(sht1.Columns("B:BP"), sht1.UsedRange)
.Cells.EntireColumn.Hidden = False ' unhide columns
If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False

.AutoFilter field:=1, Criteria1:="Change of Numbers"

.Range("A:F, BL:BO").Copy Destination:=sht2.Cells(2, "B")
.Parent.AutoFilterMode = False

.Range("H:BK").EntireColumn.Hidden = True ' hide columns
End With

Dim t As Range
For Each t In Intersect(Target, Range("B:B"))
Select Case (t.Value)
Case "Change of Numbers"
Columns("B:BP").EntireColumn.Hidden = False
Columns("H:BL").EntireColumn.Hidden = True
'do nothing
End Select
Next t

End If

safe_exit:
Application.EnableEvents = True
End Sub






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 7:41

























answered Nov 9 at 6:37









Gexas

1199




1199











  • Nope, every time there is a change anywhere on the worksheet, sheet CON is being changed. No need to do this unless a value in a cell in the B column has changed to "Change of Numbers".
    – VBasic2008
    Nov 9 at 7:05










  • Oh I see what you talking about now, I'll change my answer to correct order then.
    – Gexas
    Nov 9 at 7:39










  • That's nice. Now I want to manually trigger FilterAndCopy (run macro).
    – VBasic2008
    Nov 9 at 7:52
















  • Nope, every time there is a change anywhere on the worksheet, sheet CON is being changed. No need to do this unless a value in a cell in the B column has changed to "Change of Numbers".
    – VBasic2008
    Nov 9 at 7:05










  • Oh I see what you talking about now, I'll change my answer to correct order then.
    – Gexas
    Nov 9 at 7:39










  • That's nice. Now I want to manually trigger FilterAndCopy (run macro).
    – VBasic2008
    Nov 9 at 7:52















Nope, every time there is a change anywhere on the worksheet, sheet CON is being changed. No need to do this unless a value in a cell in the B column has changed to "Change of Numbers".
– VBasic2008
Nov 9 at 7:05




Nope, every time there is a change anywhere on the worksheet, sheet CON is being changed. No need to do this unless a value in a cell in the B column has changed to "Change of Numbers".
– VBasic2008
Nov 9 at 7:05












Oh I see what you talking about now, I'll change my answer to correct order then.
– Gexas
Nov 9 at 7:39




Oh I see what you talking about now, I'll change my answer to correct order then.
– Gexas
Nov 9 at 7:39












That's nice. Now I want to manually trigger FilterAndCopy (run macro).
– VBasic2008
Nov 9 at 7:52




That's nice. Now I want to manually trigger FilterAndCopy (run macro).
– VBasic2008
Nov 9 at 7:52

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53220237%2fcopy-rows-without-triggering-a-macro-vba%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế