hi, I'm new to vba and im trying to do a OR,NOT, AND operations on a selected range per each row, the way I want to do it get user input to select the columns first through input box then use those columns to do the operations, all the coloumns are consisting of only 0`s and 1's. if the user selects keep column 1-5 this part i'm able to do then select this range and do a OR,NOT, AND operation in each column. So if row one has a 1 is any of the columns then result = 1 and keep going till the end range
I've tried doing this but I'm counting 1 everything it occurs so if theres three 1's in row one its counting as 3 i just want output to be 1. That being said I'm also stopped by a annoying error I cant fix
The next is a NOT operation so look at each column in the selected range per row if all values a 0 increment by 1
then lastly AND which is simply is all columns in the row is 1 count as 1 keep incrementing till end of the range. If im able to do one i can do the others heres what i have so far:
I've only tried to do the NOT operation but at a loss im getting an error also where i put the *** it says range not declared and when i look into to it it says myRange is empty. Maybe I'm not declaring my range correctly. Any help will be great thank you
I've tried doing this but I'm counting 1 everything it occurs so if theres three 1's in row one its counting as 3 i just want output to be 1. That being said I'm also stopped by a annoying error I cant fix
The next is a NOT operation so look at each column in the selected range per row if all values a 0 increment by 1
then lastly AND which is simply is all columns in the row is 1 count as 1 keep incrementing till end of the range. If im able to do one i can do the others heres what i have so far:
Code:
[/FONT][FONT=arial]Sub inBox()
Dim colrow As String
'the below will take the users input
colrow = Application.InputBox("columns needed seperate with "," e.g: ""1,2,3""", Type:=2) operations colrow
End Sub
[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]
Sub operations (colrow As String)
Dim stRng As Range, endRng As Range, newRng As Range, a As Range
Dim d As Variant
Dim nxt As String
Dim myRange As Range
Dim b As Range
Dim cell As Range
Set stRng = Range("A2").End(xlToRight) '<-- firstcell
Set endRng = Cells(2, Columns.Count).End(xlToLeft) '<-- lastcell
Set newRng = Range(stRng, endRng) '<--| IDs range
For Each d In Split(Replace(colrow, " ", ""), ",") '<--| loop through
Set a = newRng.Find(what:=d, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If Not d Is Nothing Then nxt = d.Address(False) & "," '<--| if the current input is found then update nxt addresses list
Next d
nxt = nxt
Set myRange = ActiveSheet.Range(nxt).EntireC<wbr>olumn '********
i = 0
For Each b In myRange.Rows 'go into each row of selected range
r = 0 'initalise result
For Each cell In b.Cells ' go into each cell
if cell.Offset(i).Value = result then
r = r +1
Next cell
i = i + 1
Next
Cells(1, 10) = r ' output result
End Sub
[/FONT]
[FONT=arial]
I've only tried to do the NOT operation but at a loss im getting an error also where i put the *** it says range not declared and when i look into to it it says myRange is empty. Maybe I'm not declaring my range correctly. Any help will be great thank you
Last edited: