Excel transfer specific row selection from a column to neighboring column

dnjl01

New Member
Joined
Jan 19, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
As already mentioned in the title, I would like to transfer a selection from a column to the neighboring column in Excel.
The problem besides holding down the classic shift is that I have only selected individual rows of the column (where a certain value is in it) and only want to transfer this selection to the next column in order to assign a value to these specific rows there.
Exaample shown in the picture below, were I want a similar row selection of the "a" rows from column "A" at column "B". Per
Unbenannt.PNG

It would be perfect if only the corresponding rows in column B were selected in order to be able to enter a new value there directly. Thanks in advance for Help.
 
I think I understand what you want now. Try the following on a copy of your data (change the sheet name to suit). I tested it on 100k rows, came in at under 0.8 secs.
VBA Code:
Option Explicit
Sub dnjl01()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")   '<< **Change to actual sheet name**
   
    Dim ArrIn, ArrOut, alpha, i As Long, j As Long, s As String
    alpha = Array("a", "b", "c")
    ArrIn = ws.Range("B2", Cells(Rows.Count, "B").End(xlUp))
    ReDim ArrOut(1 To UBound(ArrIn), 1 To 3)
   
    For i = 1 To UBound(ArrIn)
        s = CStr(ArrIn(i, 1))
        For j = 1 To 3
            If InStr(1, s, alpha(j - 1)) > 0 Then ArrOut(i, j) = "yes" Else ArrOut(i, j) = "no"
        Next j
    Next i
    ws.Range("C2").Resize(UBound(ArrIn, 1), 3).Value = ArrOut
End Sub
Okay, one last question came up: is it possible that the column where the answers Yes/No get placed (so the column "maesure_a" from the example sheet), gets automatically created as a new column, so if I work in columns in the middle of a sheet, that no neighbouring columns will be overwritten?
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Okay, one last question came up: is it possible that the column where the answers Yes/No get placed (so the column "maesure_a" from the example sheet), gets automatically created as a new column, so if I work in columns in the middle of a sheet, that no neighbouring columns will be overwritten?
I don't fully understand what you mean. Are you talking about inserting measure_a (and b and c) columns immediately to the right of the measures column if they aren't already there? Perhaps a before and after example would help me to follow.
 
Upvote 0
Thank you for answering so far :D
So, I have created an example file that better illustrates the target. The idea is to use these Yes/No columns for later expolaritve analyses in RStudio. These are huge Excel sheets.
Unfortunately, the arrangements of the variables a/b/c are not in the same order. So far I wanted to select all "a" of the "Measures" column via Search and then wanted to transfer this selection to the column of "Measures_a" in order to be able to insert "yes" there and fill the rest with "no" using the blank selection, like shown at the column "measure_c".
(Sorry, my Excel blocks the XL2BB add in, I hope this simple table works with this here)


project_namemeasuresmeasure_ameasure_bmeasure_c
xyza, b, cyes
xyzc, byes
xyzano
xyzbno
xyza, bno
xyzano
xyza, cyes
xyzcyes
xyzb, c, ayes
xyzbno
xyzc, ayes
xyzcyes
xyza, b, cyes
xyzano
xyzbno
xyzbno
xyzc, byes
xyzcyes
xyzano
xyza, b, cyes
xyzbno
xyzb, ano
xyzcyes
xyzano
xyzbno
xyza, c, byes
xyza, bno
xyzc, a, byes
xyza, cyes

Give this code a go.

VBA Code:
Private Sub dnjl01v2()

    Worksheets("Sheet1").Range(Worksheets("Sheet1").Cells(2, 2), Worksheets("Sheet1").Cells(Ws.Rows.Count, 2).End(xlUp)).Offset(0, 1).Resize(, 3).Formula = _
        "=IF(ISERROR(FIND(RIGHT(C$1,1),$B2,1)),""no"",""yes"")"

End Sub
 
Upvote 0
Use this instead of my previous submission, there was a mistake in that one.

This code replaces the formulas with the resultant values.

VBA Code:
Private Sub dnjl01v3()

    With Worksheets("Sheet1").Range(Worksheets("Sheet1").Cells(2, 2), Worksheets("Sheet1").Cells(Worksheets("Sheet1").Rows.Count, 2).End(xlUp)).Offset(0, 1).Resize(, 3)
            
        .Formula = "=IF(ISERROR(FIND(RIGHT(C$1,1),$B2,1)),""no"",""yes"")"

        .Value = .Value

    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,539
Members
449,169
Latest member
mm424

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