How to grab the information from several cells in a row and input into another sheet

ecrodrig

Board Regular
Joined
Jan 21, 2022
Messages
99
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
SO I am trying to do the following:

IF K2 in Sheet2 = a certain number then grab the information from S2, F2, H2, I2 from Sheet 2 and input into a new sheet

Does this make sense? Hope someone... I also asked this question here: Excel Help Forum but have not received a response.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
try this:
VBA Code:
Sub test()
testnumber = 11  '  set a s required
With Worksheets("Sheet2")
 rowdata = .Range("a2:S2").Value ' load the enterie row into a variant array
End With
  If (rowdata(1, 11)) = testnumber Then
    Worksheets.Add
    Range("a1") = rowdata(1, 19) ' S
    Range("b1") = rowdata(1, 6) ' F
    Range("c1") = rowdata(1, 8) ' H
    Range("d1") = rowdata(1, 9) ' I
  End If
   
End Sub
 
Upvote 0
grab the information from S2, F2, H2, I2 from Sheet 2 and input into a new sheet
Assuming that you want those values, in that order in, say, A1:D1 of the new sheet, try this adaptation of the previous code.

BTW, the link to your cross-post does not work for me. Can you try to add a new link in your next post please?

VBA Code:
Sub Transfer_Values()
  Dim rowdata As Variant
  Const testnumber As Double = 11  '  set as required
 
  rowdata = Application.Index(Worksheets("Sheet2").Cells, 2, Array(19, 6, 8, 9, 11)) 'read relevant numbers in relevant order (+ test value) into array
  If rowdata(5) = testnumber Then
    Worksheets.Add
    Range("A1:D1") = rowdata
  End If
End Sub
 
Upvote 0
try this:
VBA Code:
Sub test()
testnumber = 11  '  set a s required
With Worksheets("Sheet2")
 rowdata = .Range("a2:S2").Value ' load the enterie row into a variant array
End With
  If (rowdata(1, 11)) = testnumber Then
    Worksheets.Add
    Range("a1") = rowdata(1, 19) ' S
    Range("b1") = rowdata(1, 6) ' F
    Range("c1") = rowdata(1, 8) ' H
    Range("d1") = rowdata(1, 9) ' I
  End If
  
End Sub
THANKS I will try this!
 
Upvote 0
Assuming that you want those values, in that order in, say, A1:D1 of the new sheet, try this adaptation of the previous code.

BTW, the link to your cross-post does not work for me. Can you try to add a new link in your next post please?

VBA Code:
Sub Transfer_Values()
  Dim rowdata As Variant
  Const testnumber As Double = 11  '  set as required
 
  rowdata = Application.Index(Worksheets("Sheet2").Cells, 2, Array(19, 6, 8, 9, 11)) 'read relevant numbers in relevant order (+ test value) into array
  If rowdata(5) = testnumber Then
    Worksheets.Add
    Range("A1:D1") = rowdata
  End If
End Sub
THANKS I will try this.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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