Posts by JF
-
-
Re: Border Class
Quote from xliteI had already thought of that. The range select did work but for some reason the formating would not. I also noted that if I tried to do it manually, I could not as well (Unless I went past the area I actually wanted). Although I would highlight the range, when I tried to use Format Cells, the dialog bog would not come up.
-
I have the below portion of code that is all of a suddent causing an error.
The report that we use with this code will be changing slightly when we upgrade the program that generates the report. The report still is output as an excel file but some of the columns are in different locations. So I had to change the lines of code to the appropriate columns. After doing so this portion of the code now errors out:Code
Display MoreLR = ActiveSheet.UsedRange.Rows.Count With Range("B2:B" & LR) .Borders(xlDiagonalDown).LineStyle = xlNone .Borders(xlDiagonalUp).LineStyle = xlNone .Borders(xlEdgeTop).LineStyle = xlNone .Borders(xlEdgeBottom).LineStyle = xlNone .Borders(xlEdgeRight).LineStyle = xlContinuous .Borders(xlEdgeRight).Weight = xlMedium .Borders(xlEdgeRight).ColorIndex = 1 End With
I get a "Unable to set the LineStyle property of the Border Class" error (Run Time Error 1004) when it attempts to set a border on the right edge of the range.
In my sample Data, LR calculates to a 6 as this is the last row of data. I tried to change as follows:
but that gave the same result.
if I change it to:
then the code runs.... I can not figure out why. I never had this problem previously. Can anyone help with this?
Also just found out if I modify as follows it runs:
-
Re: Countif with 2 Spreadsheets
Quote from cbanksyes, that would be great. but i am needing this in vba. I am great with functions but vba is what i am needing. thanks for your help
I used a range of a1:b24 for the test data on my "Data Sheet" tab and a1:a6 on "Sheet2" tab. I used the following code:
[code]
With Range("c1:c6")
.FormulaR1C1 = "=SUMPRODUCT(('Data Sheet'!R1C1:R24C1=RC1)*('Data Sheet'!R1C2:R24C2=1))"
.Copy
.PasteSpecial Paste:=xlPasteValues
End With[code]
it put the sumproduct formula in c1-c6, then copyied and did a paste special/values to that range. See the attached
-
Re: Pass Value from User Form to Code
Thanks, Yes I did originally have the public variable in the this workbook area. Not a big deal for me, I can use it in either area. Thanks for the info.
-
Re: Pass Value from User Form to Code
Quick Question....
When I used the code in the "This workbook" section, it did not work. However when I put it in a standarrd module it did.... Was wondering why it does not work from the "this workbook" area?
-
Re: Using a Message Box to pick someone
Quote from Andy Pope: D I thought it was too simple a question. I just didn't read it right.
So a variation on your post.
[vba]Sub Buton1()
Static clicknumber As Long
clicknumber = clicknumber + 1
MsgBox Choose(clicknumber, "Tom", "Sally", "Jane")
If clicknumber > 3 Then clicknumber = 0End Sub[/vba]
Andy,
Just noticed a problem with your's.. it errors after the third time... I modified it as follows and it seemed to correct it.
-
Re: Using a Message Box to pick someone
Quote from Andy Pope: D I thought it was too simple a question. I just didn't read it right.
So a variation on your post.
[vba]Sub Buton1()
Static clicknumber As Long
clicknumber = clicknumber + 1
MsgBox Choose(clicknumber, "Tom", "Sally", "Jane")
If clicknumber > 3 Then clicknumber = 0End Sub[/vba]
I like it... your's is shorter and doesn't require the use of a public variable as well....
-
-
Re: Using a Message Box to pick someone
Quote from Andy PopeHi,
Assign the macro X to your button
[vba]Sub x()MsgBox "Name 1", vbOKOnly
MsgBox "Name 2", vbOKOnly
MsgBox "Name 3", vbOKOnly
End Sub[/vba]Andy,
Won't this solution just show three messages (one after the other) with just one click of the button? Unless I read his post wrong, he wanted the name to change with each succesive click on the button itself...
-
Re: Using a Message Box to pick someone
Quote from stevehorton09Good weekend to you all,
Basically I want a button that once pressed generate a message box that says a persons name. There are 3 names, so the message box should show name 1 1st and then when pressed again show name 2 and you guessed it then name 3!
If anyone could let me know how to do this or have teh code that would be great
After you add your button to the sheet, create the below macro and point the button to it.
-
Re: Pass Value from User Form to Code
Thanks Andy,
I was able to get it with the public variable method. I had figured it out last night about 40 minutes after I posted. But good to see the other methods as well.
-
I have created a custome User Form with three option buttons inside a frame.
How do I set the value for each button and then how do I pass that value back to the code that opened the form (after closing the form upon a selection?
what I have so far is:
Code
Display MoreSub Test2() UserForm1.Show Select Case List Case 1 Range("b1").Value = "List 1" Case 2 Range("B1").Value = "List 2" Case 3 Range("B1").Value = "List 3" End Select End Sub
in the form I have the following code associated with each of the butons (but I do not think I have it right). Isn't there a way (becasue I have them in a frame) to shorten the code?
-
Re: Checking for an error
Quote from thomachIf I remember correctly, if there are no zeros present, then your FIND will set SR1 = 0. You might want to verify this. If correct, then you can use:
Thanks TOMACH, this worked perfectly
-
I have the following piece of code:
CodeSR1 = Selection.Find(What:="0", After:=ActiveCell, LookIn:=xlFormulas, LookAt _ :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False).Row Rows(SR1 & ":" & tr1).Delete Shift:=xlUp
what I need to know is how to trap the in the event it does not find any (in my case the column will only contain 1's or 0's. If there are no 0's then it should skip the line:
and continue with the line after that (which happens to be return to the macro that start the marcor this code is in)
-
Re: Use a With vs For Next
Quote from norieAs far as I can see you won't be able to use that method.
Why not use an empty column to put a formula in and the copy and paste special to F as values?
Thanks Norie, I thought of that but I am working with a small amount of data so it does not take long for the loop to run. I was just trying to see if there was a more efficient way of doing it (for my own learning purposes).
-
I have the following bit of code. While this code does what it is supposed to, is it possible to use the With command vs using the for/next loop.
CodeFor x = 2 To Range("F65536").End(xlUp).Row 'MsgBox ("left of cell is " & Left(Range("F" & x), 4)) If Left(Range("F" & x), 4) = "PERM" Then Range("F" & x).Value = "Hard Bounce" ElseIf Left(Range("F" & x), 4) = "TEMP" Then Range("F" & x).Value = "Soft Bounce" Else End If
so something like
Codelr = range("F65536").end(xlUp).row with range(cells(2,6), cells(lr,6) if left( ,4)="PERM"...... Elseif left( ,4)="TEMP"..... End With
I'm not sure how to referance the cells for the with method. Can it be done or is the for/next loop the best way?
-
Re: need a formula on page 2 to search data on page 1
You could try something like this: In my test, I had the sample data in rows 1-8 (row 1 as header).
-
Re: dividing a .csv file into 2 smaller files
Quote from need_a_nameHi Rich,
Tried that and it still takes 40 min to get thry 60000 rows of data.
Sincerely,
gregHere is code that I use to import large .txt files into excell... it automatically parses at 65536 rows. I have done in excess of 100,000 rows in less than 1 minute with it.
Code
Display MoreSub LargeFileImport() 'Dimension Variables Dim ResultStr As String Dim FileName As String Dim FileNum As Integer Dim Counter As Double 'Ask User for File's Name FileName = InputBox("Please enter the Text File's name, e.g. test.txt") 'Check for no entry If FileName = "" Then End 'Get Next Available File Handle Number FileNum = FreeFile() 'Open Text File For Input Open FileName For Input As #FileNum 'Turn Screen Updating Off Application.ScreenUpdating = False 'Create A New WorkBook With One Worksheet In It Workbooks.Add template:=xlWorksheet 'Set The Counter to 1 Counter = 1 'Loop Until the End Of File Is Reached Do While Seek(FileNum) <= LOF(FileNum) 'Display Importing Row Number On Status Bar Application.StatusBar = "Importing Row " & _ Counter & " of text file " & FileName 'Store One Line Of Text From File To Variable Line Input #FileNum, ResultStr 'Store Variable Data Into Active Cell If Left(ResultStr, 1) = "=" Then ActiveCell.Value = "'" & ResultStr Else ActiveCell.Value = ResultStr End If 'For Excel versions before Excel 97, change 65536 to 16384 If ActiveCell.Row = 65536 Then 'If On The Last Row Then Add A New Sheet ActiveWorkbook.Sheets.Add Else 'If Not The Last Row Then Go One Cell Down ActiveCell.Offset(1, 0).Select End If 'Increment the Counter By 1 Counter = Counter + 1 'Start Again At Top Of 'Do While' Statement Loop 'Close The Open Text File Close 'Remove Message From Status Bar Application.StatusBar = False End Sub
I found this code here on Ozgrid quite some time ago.
-
Re: text with number into number
Quote from SetiWelcome to OzGrid.
Assuming that your sample is a complete reflection of your data, you can try this:
=LEFT(A1,6) and format to 2 decimal places.
More complex answers might include a FIND to look for the space between the number and "Pts".
This would work with one exception, the result could appear as a number but actually be seen by excel as text. to get around this, try the following:this will pull all data to the left of the space (in case you have more than 6 digits prior to the space "Pts". It will then convert to an actual number format so you can do calculations if needed.
BTW, this is a tip from Dave Hawley's book Excell Hacks - Thanks Dave....