Re: Compare 2 Columns To Another Sheet & Highlight Matches
G'day
I've edited the code to add some comments. Hope that explains it for you.
Tony
Re: Compare 2 Columns To Another Sheet & Highlight Matches
G'day
I've edited the code to add some comments. Hope that explains it for you.
Tony
Re: Macro To Compare And Highlight Cell Contents
Hi
See how this goes.
Sub aaa()
'dimension 2 variables as worksheets, then set to the relevant sheets
Dim SrcSH As Worksheet
Dim DataSH As Worksheet
Set SrcSH = Sheets("Sheet1")
Set DataSH = Sheets("PBIC 8")
'create an array of the 2 headings to be checked on the source sheet
headarr = Array("REGISTRATIONNBR", "SERIALNBR")
'cycle through the 2 heading items
For i = LBound(headarr) To UBound(headarr)
'work out which column has the heading
coll = WorksheetFunction.Match(headarr(i), SrcSH.Rows("1:1"), 0)
'make a range of the relevant data in that column
Set rng = SrcSH.Range(Cells(2, coll), Cells(Rows.Count, coll).End(xlUp))
'loop through the cells in the range
For Each ce In rng
'if the cell has something in it then process
If Not ce = "" Then
'use find to set a variable with the result
Set findit = DataSH.Cells.Find(what:=ce.Value)
'something is found
If Not findit Is Nothing Then
'make a note of the address for the first found entry
firstAdd = findit.Address
'color the items found, then redo the find. Keep going until you come back
'to the first address. Covers multiple appearances of an item.
Do
findit.Interior.ColorIndex = 3
ce.Interior.ColorIndex = 3
Set findit = DataSH.Cells.Find(what:=ce.Value, after:=findit)
Loop Until findit.Address = firstAdd
End If
End If
Next ce
Next i
End Sub
Display More
Tony
Re: Data Validation Source
Hi
Try this. Right click on sheet1 tab, select view code, and paste in the code below.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set rng = Range("C12:C15")
strr = ""
If Not Intersect(Target, rng) Is Nothing And Not IsEmpty(Target.Offset(0, -1)) Then
Target.Validation.Delete
For Each ce In Range(Cells(2, Target.Column - 1), Cells(7, Target.Column - 1))
If ce.Value = Target.Offset(0, -1) Then strr = strr & ce.Offset(0, -1).Value & ","
Next ce
Target.Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=Left(strr, Len(strr) - 1)
End If
End Sub
Display More
At this stage it is only designed to work on the range C12:C15.
Select C12 and you should see a list of names. Make a change to the selection in B12, and the dropdown list should change.
HTH
Tony
Re: Import Newest Text File
Hi
Does this give you any help?
Sub bbb()
ChDrive "c"
ChDir "c:\temp"
Set fs = CreateObject("Scripting.filesystemobject")
timee = 2400
Dim fname As String
Do
fname = Format(Now(), "ddmmyy") & timee & ".txt"
timee = timee - 100
Loop Until fs.fileexists(fname)
MsgBox fname
End Sub
Display More
If you don't want to change the drive / path, then you could include those details into the fname string.
Tony
Re: Wildcards Index/match
Hi
Enter a space in I1, then array enter (ctrl, shift, enter) the formula
=INDEX($I$1:$I$5,MAX(IF(ISNUMBER(MATCH("*"&$H$2:$H$5&"*",B2,0)),ROW($H$2:$H$5),"")))
in C1 and copy down to C8.
HTH
Tony
Re: Filter By String Criteria
Hi
Could you use a test along the lines of
If Left(Cells(i, 1).Value, 4) = "L-0." And Len(Cells(i, 1).Value) = 7 Then
Cells(i, 1).EntireRow.Delete
End If
as a basis for your deletion? You could still use your input selection method to work out the number of characters before the *, and use the length of the selection string to make dynamic variables.....
Tony
Re: Dual Headings Match
Hi
Here it is expanded for your new sample, and absoluted.
=INDEX($B$2:$E$2,0,MAX(IF(MIN(IF($B$3:$E$3=$I21, OFFSET($B$3,MATCH($H21,$A$4:$A$16,0),0,1,4),MAX($B$4:$E$16)))=OFFSET($B$3,MATCH($H21,$A$4:$A$16,0),0,1,4),COLUMN($B$5:$E$5)-1,"")))
Tony
Re: Formula In 2 Cells To Populate In Only One Cell
Hi
Not sure I follow. Do you want to be able to enter a value in A2, and have a formula automatically generated in B2? If so, then you will need to have an event macro with a trigger of a change to a cell in column A.
Is that what you want to do?
Tony
Re: Dual Headings Match
Hi
Try
=INDEX(B2:E2,0,MAX(IF(MIN(IF(B3:E3=I21,OFFSET(B3,MATCH(H21,A4:A6,0),0,1,4),MAX(B4:E6)))=OFFSET(B3,MATCH(H21,A4:A6,0),0,1,4),COLUMN(B5:E5)-1,"")))
array entered.
Tony
Re: Formula In 2 Cells To Populate In Only One Cell
Hi
How about
=CONCATENATE(IF(IF(C2="",0,C2)>B2,"Ave>Max",IF(IF(C2="",0,C2)<A2,"Ave<Min",""))," ",IF(B2=0,IF(B2<A2,"Min>Max",""),IF(B2<A2,"Min>Max","")))
Tony
Re: Transfer Data From 2 Worksheets Into 1 - Macro
Hi
Your Identified data has an extra column of "keep" data (column BJ - Q1 2008) than the Unidentified data sheet. Your Desired End Result sheet doesn't show this heading. How do you want the extra column of data handled?
Tony
Re: Transfer Data From 2 Worksheets Into 1 - Macro
Hi
See how this goes.
Sub MergeSheets()
Dim OutSH As Worksheet
Set OutSH = Sheets("All Data - End Result")
OutSH.Cells.ClearContents
With Sheets("Identified")
lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
.Range("A6:H" & lastrow).Copy Destination:=OutSH.Range("A6")
End With
With OutSH
.Columns("G").EntireColumn.Delete
.Columns("F").EntireColumn.Delete
.Columns("D").EntireColumn.Delete
End With
With Sheets("unidentified")
lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
outrow = OutSH.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
.Range("A7:C" & lastrow).Copy Destination:=OutSH.Cells(outrow, 1)
.Range("E7:E" & lastrow).Copy Destination:=OutSH.Cells(outrow, 4)
.Range("F7:F" & lastrow).Copy Destination:=OutSH.Cells(outrow, 5)
End With
OutSH.Columns("A:E").AutoFit
End Sub
Display More
HTH
Tony
Re: Extract Unique Names From A Column
Hi
Go to Data, Filter, Advanced Filter. Make sure you select the copy to another location, and unique options.
HTH
Tony
Re: Text Box Value Validation
Hi
You could do something like
On Error Resume Next
tester = CDbl(TextBox1.Value)
On Error GoTo 0
If TextBox1.Value = "" Then
MsgBox ("The Value MUST be Entered"), vbOKOnly, "Value of Something"
exit sub
end if
You can put that in the end processing like the other test, and / or on a textbox_exit event.
HTH
Tony
Re: Text Box Value Validation
Hi
Where is the textbox? Is it in a form, or directly on the spreadsheet.
If on a form, then you could do something like
Do
If TxtBox1.Value = "" Then
MsgBox ("The Value MUST be Entered"), vbOKOnly, "Value of Something"
TxtBox1.SetFocus
Exit Sub
End If
Loop Until TxtBox1.Value <> ""
ws.cells(r,2).value = TxtBox1.Value
HTH
Tony
Re: Macro To Transpose & Duplicate
Hi
Try the attached. I've put the macro into your source file, and changed it so that the output will go to sheet3.
Make sure you are on sheet1 when running, and the ranges selected match your colored source ranges.
Runs OK for me.
Tony
Re: Macro To Transpose & Duplicate
Hi
See if this gets you going.
I've done no error checking to make sure that you have selected the same number of rows in both selection. When the first input box comes up, use the cursor to select the yellow range. For the second, select the green range. You must have an output sheet called sheet2. Any existing data on that sheet will be deleted.
Sub ccc()
Dim HorRng As Range, VertRng As Range
Dim OutSH As Worksheet
Dim HorRngRows As Integer, HorRngCols As Integer, VertRngRows As Integer, VertRngCols As Integer
Dim OutRow As Integer
Set HorRng = Application.InputBox("What is the first range", Type:=8)
Set VertRng = Application.InputBox("What is the second range", Type:=8)
Set OutSH = Sheets("Sheet2")
HorRngCols = HorRng.Columns.Count
HorRngRows = HorRng.Rows.Count
VertRngRows = VertRng.Rows.Count
VertRngCols = VertRng.Columns.Count
OutSH.Cells.ClearContents
OutSH.Range("A1").Resize(1, HorRngCols).Value = HorRng.Resize(1, HorRngCols).Value
For i = 2 To HorRngRows
For j = 1 To VertRngCols
OutRow = OutSH.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
OutSH.Cells(OutRow, 1).Resize(1, HorRngCols).Value = HorRng.Cells(i, 1).Resize(1, HorRngCols).Value
OutSH.Cells(OutRow, 1).Offset(0, HorRngCols).Value = VertRng.Cells(1, j).Value
OutSH.Cells(OutRow, 1).Offset(0, HorRngCols + 1).Value = VertRng.Cells(i, j).Value
Next j
Next i
End Sub
Display More
Tony
Re: Blank Cell When No Value Is Calculated
Hi
Try
D15: =IF(AND(ISBLANK(B15),ISBLANK(C15)),"",B$6-SUM(B$12:B15)+SUM(C$12:C15))
and copy down.
Tony
Re: Prevent Duplicate Through VBA Userform
Hi
See if this helps.
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a part number
If Trim(Me.txtPart.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "Please enter the Code"
Exit Sub
End If
If WorksheetFunction.CountIf(ws.Range("A:A"), txtPart.Value) = 0 Then
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtPart.Value
ws.Cells(iRow, 2).Value = Me.txtLoc.Value
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 4).Value = Me.txtQty.Value
'clear the data
Me.txtPart.Value = ""
Me.txtLoc.Value = ""
Me.txtDate.Value = ""
Me.txtQty.Value = ""
Me.txtPart.SetFocus
Else
MsgBox "This code already exists in the database."
End If
End Sub
Display More
Tony
Re: Data Validation Limitation On No Of Cells Applied & Large Non Contigous Range
Hi
Perhaps an event macro that will remove any existing data validation from the entire range, and create the validation for the relevant selected cell...
HTH
Tony