Make Code work from Splash Page "Line Update"

Nlhicks

Active Member
Joined
Jan 8, 2021
Messages
264
Office Version
  1. 365
Platform
  1. Windows
My code currently only works if I go to Sheet2 but I really want it to work from "Line Update". Not sure how to make this happen I am open to suggestions.
Sub TryUpdate()

Dim RngRange01 As Range

rngRang01 = Range("A" & Rows.Count).End(xlUp).Row
Range("A2:P" & rngRang01).SpecialCells(xlCellTypeVisible).Select


If Worksheets("Line Update").Range("C11") <> Worksheets("Line Update").Range("F11") Then
Worksheets("Sheet2").Range("B2:B" & rngRang01).Value = Worksheets("Line Update").Range("F11").Value

End If

If Worksheets("Line Update").Range("C12") <> Worksheets("Line Update").Range("F12") Then
Worksheets("Sheet2").Range("C2:C" & rngRang01).Value = Worksheets("Line Update").Range("F12").Value

End If

If Worksheets("Line Update").Range("C13") <> Worksheets("Line Update").Range("F13") Then
Worksheets("Sheet2").Range("D2:D" & rngRang01).Value = Worksheets("Line Update").Range("F13").Value

End If

If Worksheets("Line Update").Range("C14") <> Worksheets("Line Update").Range("F14") Then
Worksheets("Sheet2").Range("E2:E" & rngRang01).Value = Worksheets("Line Update").Range("F14").Value

End If

If Worksheets("Line Update").Range("C15") <> Worksheets("Line Update").Range("F15") Then
Worksheets("Sheet2").Range("F2:F" & rngRang01).Value = Worksheets("Line Update").Range("F15").Value

End If

If Worksheets("Line Update").Range("C16") <> Worksheets("Line Update").Range("F16") Then
Worksheets("Sheet2").Range("G2:G" & rngRang01).Value = Worksheets("Line Update").Range("F16").Value

End If

If Worksheets("Line Update").Range("C17") <> Worksheets("Line Update").Range("F17") Then
Worksheets("Sheet2").Range("H2:H" & rngRang01).Value = Worksheets("Line Update").Range("F17").Value

End If

If Worksheets("Line Update").Range("C18") <> Worksheets("Line Update").Range("F18") Then
Worksheets("Sheet2").Range("I2:I" & rngRang01).Value = Worksheets("Line Update").Range("F18").Value

End If

I had a shorter version of this created and it worked for a little while but it quit working so I am not sure it was the right one.
 

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.
This one works also but again it expects me to be on Sheet2 for it to work

Sub TryUpdate()

Dim RngRange01 As Long, i As Long
Dim WS As Worksheet

Set WS = Sheets("Sheet2")
rngRang01 = Range("A" & Rows.Count).End(xlUp).Row
Range("A2:P" & rngRang01).SpecialCells(xlCellTypeVisible).Select

With Worksheets("Line Update")

For i = 11 To 18
If Range("C" & i) <> Range("F" & i) Then
WS.Cells(2, i - 9).Value = Range("F" & i).Value
End If
Next i
End With


End Sub
 
Upvote 0
Why not use the code I gave you a few days ago & just change the ranges to reflect columns C & F, rather than B & E?
 
Upvote 0
Solution
I did that but, it only runs if I am on Sheet2. I want it to run from sheet Line Update. How can I change it to make that work?
 
Upvote 0
The code I supplied will do exactly what you want if you just change the columns like
Excel Formula:
Sub TryUpdate()
   Dim RngRange01 As Long, i As Long
   Dim Ws As Worksheet

   Set Ws = Sheets("Sheet2")
   With Worksheets("Line Update")
      rngRang01 = .Range("A" & Rows.Count).End(xlUp).Row
      For i = 11 To 18
         If .Range("C" & i) <> .Range("F" & i) Then
            Ws.Cells(2, i - 9).Value = .Range("F" & i).Value
         End If
      Next i
   End With
End Sub
 
Upvote 0
It still makes me be on Sheet2 for the code work. It will not work if I am on the sheet I am trying to run it from.
 
Upvote 0
Do I have to open the sheet I want to perform actions on or is there a way around that?
 
Upvote 0
Is the name of the sheet as seen on the tab Sheet2?
 
Upvote 0
Okay I added Worksheets("Sheet2").Activate and now it will run from the splash page however, it now takes me to sheet 2 and I have to go back to sheet Line Update manually. How can I go back to sheet Line Update automatically?
 
Upvote 0
Line Update is my Splash page where I am running the entire program from. Sheet2 contains my data I am filtering and changing
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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