Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 49987 articles
Browse latest View live

Looped Find & Delete row, Code works but too slow

$
0
0
Hi,
My data set is >320,000 rows deep, 45 columns. There is column headed by "Record Status Code" populated by "1" or "3". Another column "Transaction ID" has a number in string format.

My instructions were:
"9. All claims with RecordStatus = 3 are reversals. We need to remove them, along with the original claim they reversed. To find the original claim, look at the Transaction ID for the reversal, and replace the last digit (1) with a 0."

In other words, for every row with Record Status Code = "3", also find the row containing Transaction ID with altered last digit, and delete both rows.

I wrote a code that seems to work. However, it takes way too long. Is there an alternative/optimized method?


Code:

Sub Step9()
Dim x As String, y As String
Dim a As Long
Dim Tcol As Range, Rcol As Range

Application.ScreenUpdating = False

With ActiveWorkbook.ActiveSheet
Set Rcol = .Columns(Application.WorksheetFunction.Match("Record Status Code", Range("1:1"), 0))
Set Tcol = .Columns(Application.WorksheetFunction.Match("Transaction ID", Range("1:1"), 0))
   
    Do Until Rcol.Find("3") Is Nothing
        a = Application.WorksheetFunction.Match("3", Rcol, 0)
        x = Tcol.Cells(a).Text
        y = Left(x, Len(x) - 1) & "0"
        Tcol.Find(x).EntireRow.Delete
        Tcol.Find(y).EntireRow.Delete
    Loop

End With

Application.ScreenUpdating = True

End Sub


SaveAs a Worksheet to another file/folder while keeping the original open/active

$
0
0
I have an Excel Worksheet (let's call it "AA.xlsm") which uses VBA code to loop through column A, update column B with some results/values, and then (for each value in column A) SaveAs the worksheet into a different filename/path as a ".csv" type file.

My line of code for the SaveAs is as follows:
Workbooks("AA.xlsm").SaveAs LEpath & CurrFldr, FileFormat:=xlCSV

My problem is that my original worksheet, AA.xlsm, gets closed whereas I need it to stay open/active after each SaveAs iteration.

I hope I made myself clear .... ~Dan

How to Calculate Number of Overtime Hours but Only for Weekday

$
0
0
Hello,

I need help with a formula that will calculate the number of overtime hours, but only for weekdays.

I have in:
Column A1: Date of Work (for example, December 24, 2012)
Column A2: Number of Hours worked (for example, 8)
Column A3: Day of the Week (for example, Monday)

I want to put the formula in Column A4, which will show "Number of Overtime Hours (Weekdays)".
Basically, anything over 8 hours will be overtime. So in Column A4, I want something that says if A2>8 and A3 is Monday-Friday, then A2-8.
So lets say for example it is 12 hours on a Tuesday. I'm guessing the formula would be something like: =IF(A2>8 AND MONDAY-FRI???, (A2)-8,0)=4.

Can anyone help? Thanks,

Tony

Cleaning up code (getting rid of ActiveCell.Offset(x,x).Select usage)

$
0
0
I have a macro that formats some reports for me. It looks for a cell near the end of the bottom with the value "Grand Total:" and then modifies the cells relative to the cell where it found "Grand Total:"

This is what the code looks like right now:

Code:

    Cells.Find(What:="Grand Total:", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
   
    If ActiveCell.Offset(0, 2) = 0 Then GoTo BillOnly
   
    ActiveCell.Offset(0, 1).Select
    Selection.ClearContents
    ActiveCell.Offset(0, 1).Select
    Selection.ClearContents
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
    ActiveCell.Offset(-1, 0).Select
    ActiveCell.FormulaR1C1 = "=R[-1]C[-1]"
    ActiveCell.Offset(0, -1).Select
    ActiveCell.WrapText = False
    ActiveCell.Offset(-1, -7).WrapText = False
        Range("D" & ActiveCell.Offset(-1).Row & ":I" & ActiveCell.Offset(-1).Row).UnMerge
    ActiveCell.RowHeight = 11.25
   
    If NSFfee = False Then
        ActiveCell.FormulaR1C1 = "Less fees"
    ElseIf NSFfee = True Then
        ActiveCell.FormulaR1C1 = "Less NSF checks, NSF fees and billing fees"
    End If
   
    ActiveCell.Offset(1, -1).Select
    If ActiveCell.Offset(0, 2) > 0 Then GoTo DueURS
    If ActiveCell.Offset(0, 2) <= 0 Then GoTo DueCommunity
    GoTo ErrorEnd
   
BillOnly:
    ActiveCell.Offset(0, 1).Select
    Selection.ClearContents
    ActiveCell.Offset(0, 1).Select
    Selection.ClearContents
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
    ActiveCell.Offset(-1, 0).Select
    ActiveCell.FormulaR1C1 = "=R[-1]C[-1]"
    ActiveCell.Offset(0, -1).Select
    ActiveCell.FormulaR1C1 = "Total fees"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "Total due to URS of WA"
    GoTo FIN148EndSave

DueURS:
    ActiveCell.FormulaR1C1 = "Total due to URS of WA"
    GoTo FIN148EndSave
DueCommunity:
    ActiveCell.FormulaR1C1 = "Total reimbursement due to community"
    GoTo FIN148EndSave

I figure the best way is to have it store the address of where it finds "Grand Total:" into a variable called GTcell and then work off of Range(GTcell).Offset(x,x) but I could be wrong in my approach, I am fairly newb with VBA. This is how I have started to try to recode, but I keep getting errors.

Code:

    Dim GTcell As Range
       
    Set GTcell = Cells.Find(What:="Grand Total:", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Address(0, 0)
   

  If Range(GTcell).Offset(, 2) = 0 Then GoTo BillOnly
   
  Range(GTcell & ":" & GTcell.Offset(, 2)).ClearContents

148start.xls is a sample of how the report starts and 148end.xls is a sample of how the report should end when the GTcell.Offset(, 2).Value <> 0

Thank you so much for your attention and help!

Event Procedure - Worksheet_SelectionChange

$
0
0
Hello,

I have an excel with data validation lists in c11 and c19, based on code selected in c11, the drop down list in c19 changes to ones that are linked to that specific value in c11.

I want to add Worksheet_SelectionChange so that when each time the value in c11 is changed, c19 value is cleared automatically.

Can someone plz help me with that?

Thanks!

[SOLVED] Copy data from one workbook to another based on dropdown filter menus - marco

Getting error 1004

$
0
0
Hi friends,
Please see the attached file and suggest me a correction.
I want a sum output in column 'AN' of 'G, K, O,S,W,AA,AE,AI,AM' columns. I used 'OR' function in range.

Thanking you in anticipation.

Regards,

Mukesh
Attached Files

to write a macro that opens another worksheet when choose from drop down list

$
0
0
I need to write a macro that opens another worksheet when choose from drop down list

inverse distance weighting function???

$
0
0
I have longitude/longitude points in which I would like to apply inverse distance weighting statistics to.

I would like to possibly create a chart with the results...

see link below for explanation of inverse distance weighting.

http://help.arcgis.com/en/arcgisdesk...814100-web.png


is there a function in excel or access that I would be able to use to achieve this goal?

color datapoint in chart based on vba macro

$
0
0
i have created a chart where X axis holds values in column A (showing dates) and Y axis holds values in column B (showing prices). the chart has been plotting on a separate sheet.

I am trying to write a excel vba code where for specific values of Y based on if/than statement in column C, the corresponding datapoint in the chart is resized/colored (essentially highlighted on chart).

I am struggling here a bit.

I appreciate your input.

thanks.

nqh

Brain-wracking Excel Problem Driving me to Drink Heavily

$
0
0
Hey everybody!

I've been working on a problem that is driving me insane. I basically need to create a Group based on three columns (in the example, they are columns B, C, and H).

For Each Group (Group = Group Letter, Group #, and Zone combined) I need the adjusted retail to equal the recommended retail provided. No Group number that is less (in rank) than the number with the recommended retail can be higher than the recommended retail. Each item (group #) that is less (in rank) than the item (Group #) with the recommended retail must be lower by $10. Each item lower in rank in that group must then go down by $10.

Example: Filters,L,Zone 510 - Group #2 is higher than the recommended #3.

Heaters,A,Zone 512 - Group #6 is higher than recommended retail. Need it to change to $2,389.99, and then need every other item to go down by at least $10 below that (Group #5 in that group would need to change to $2,379.99). If it is already lower than it does not need to change (so Group#4 in that group would be OK).


This is about as hard to explain as it is to do.. If any of you have any macro ideas or formulas that could help, I would really appreciate it. I know the basics of writing VBA code but I am nowhere experienced enough to formulate what I need to do in my mind.

Thanks again in advance!Excel Drinking Problem Script Example.xls

Add miising dates to stock market data in excel 2010

$
0
0
I have Stock market daily data for last 30 yrs. for my cycle analysis would appreciate a macro which would insert date which is missing
appreciate the help
thanks
svshah

VBA - Edit a value to make Excel recognize it as a time (ie 011:25:46)

$
0
0
Hi everyone

I'm using the following bit of code which automates the copy and pasting of a VLOOKUP formula which pulls in call times from other workbooks.

Code:

Sub Call_times2()
'
' Call_times Macro
' Copy and paste VLOOKUP to pull call times into GP Report
'

'
    Dim i As Long
    i = 3
    Do
        i = i + 1
    Loop While Range("A" & i).Value = "SG"
    Range("U4").FormulaR1C1 = "=VLOOKUP(RC[-18],'[Call times - Yesterday.xls]Recovered_Sheet1'!R1C1:R400C11,11,0)"
    Range("V4").FormulaR1C1 = "=VLOOKUP(RC[-19],'[Call times - Five days.xls]Recovered_Sheet1'!R1C1:R400C11,11,0)"
    Range("W4").FormulaR1C1 = "=VLOOKUP(RC[-20],'[Call times - Month.xls]Recovered_Sheet1'!R1C1:R400C11,11,0)"
    With Range("U4:W" & i - 1)
        .FillDown
        .Value = .Value
    End With
End Sub

Most times are in the format 01:25:43 and are recognized by Excel as times after the ".Value = .Value" part of the macro. The ones that still aren't recognized are where the values have three digits in the hours section, for example 012:34:28. These values can't be sorted or worked with.

How can I get the macro to recognize those values with three digits for hours and remove the first zero before the ".Value = .Value" section?

I appreciate any help anyone can give me.

Cheers!

Macro to change multiple external Links

$
0
0
I'm looking for a macro that will automatically change several external links in about 200 excel files..each file has about 10 links that need to be changed on a monthly basis. Anything that can speed this process up will help. I have gotten the below macro to work..but I would like it to do all the links in the file, not sure how to make that happen. Thanks for the help!

Code:

Sub ChangeLink()
    Dim OldLink As String
    Dim NewLink As String
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    OldLink = ws.Range("A1").Value
    NewLink = ws.Range("A2").Value
    ThisWorkbook.ChangeLink Name:=OldLink, NewName:=NewLink, Type:=xlExcelLinks
End Sub

Commandbutton to cut and paste highlighted row

$
0
0
Hi all,
I have 3 sheets
In sheet1 I have rows numbered from 1-19

What I want to achieve:
- Select row 3 by highlighting third cell in column1
- Then press command button1 to transfer it to sheet2 and button2 to transfer row to sheet3.
I have tried many methods but can not get it right.
Some help please
Thanks
Kind regards :)
Attached Files

Is shared workbook open?

$
0
0
Hi all,

I have researched this but can't seem to find anything that works for me. I have tinkered.

I have an Excel file (xlsm) on a shared network. Quite simply (ahem!) I want to determine if the file is open (in any guise - read only, etc) from another workbook.

Code:

If open Then MsgBox("Open")

ElseIf: MsgBox("Closed")

Something like that anyway.

Worksheet message box accessed manually and using macros

$
0
0
Hi all,

I've got a workbook which holds lots of information on a number of worksheets. I've used shapes/macros to create buttons on sheet 1. These buttons select the appropriate worksheet and filters information to make it simple for the layman to find what they want.

Navigating manually using the worksheet tabs won't reset the filters and may make subsequent searches incomplete/fail so I've added a message box to remind the user to navigate using the buttons.

Is there anyway of identifying if the worksheet was selected using one of the macros and skipping the message box?? Ie. can we treat a manual click differently to selecting using a macro?

Thanks in advance.

Macro to Populate Textbox with Restricted Value

$
0
0
I am making a Dashboard for my workbook. I have inserted a textbox (call it "Textbox1" for the purposes of this study) on "Sheet1". I am wanting this textbox to go through all active sheets (excluding "Sheet1", "Sheet2", "Sheet3") and provide back the most current date from cell "F5" based upon a restriction that the WS cell "F3" has to be "Compliance". The intent would be that this would be a workbook open based code that way when the workbook opens it provides the user with the last completed date. Ex. "Sheet4" has August 29th, 2013 in cell F5, "Sheet5" has October 8th, 3013 in cell F5, "Sheet6" has November 7th, 2014 in cell F5 but no "Compliance" in F3. The value returned into the textbox would be October 8th, 2013.

Problem with VBA Hyperlinks.Add taking Anchor from RefEdit in Userform

$
0
0
Hello All,

I was hoping to get some help with a problem I am having. I've googled forums and tinkered with the code for over a day now and still get errors in adding a hyperlink.

I've tried to create a simple Userform that allows users who aren't that tech savvy to click on a hyperlink (or a button somewhere) and edit a hyperlink.
The Userform has three different inputs:
Address - which comes from Application.FileDialog(msoFileDialogFilePicker)
TextToDialog - comes from manual textbox input
Anchor - which comes from RefEdit control

The problems arise around the Anchor (I'm assuming, since when I get various errors, the yellow arrow is on the line with "Anchor: RefEdit.Value"

Any help with the problem would definitely help. Thank you in advance

Below is my code:

Code:

Option Explicit
Public StrPath As String

Private Sub AcceptButton_Click()

'The following is another solution, that works. A formula is not desired though
'Range(RefEdit).Formula = "=HYPERLINK(""" & HyperSource & """,""" & HyperText & """)"

'The following 6 lines just show outputs for variables
Range("B12").Value = "Address"
Range("C12").Value = HyperSource
Range("B13").Value = "TextToDisplay"
Range("C13").Value = HyperText
Range("B14").Value = "Anchor"
Range("C14").Value = RefEdit.Value

ActiveSheet.Hyperlinks.Add _
    Address:=HyperSource, _
    TextToDisplay:=HyperText, _
    Anchor:=RefEdit.Value
   
Unload Me
UserForm1.Hide
End Sub

Code:

Private Sub BrowseButton_Click()
Dim StrPath As String
      With Application.FileDialog(msoFileDialogFilePicker)
        .InitialFileName = Application.DefaultFilePath & "\"
        .Title = "Please select a file to hyperlink"
        .Show
        If .SelectedItems.Count <> 0 Then
          StrPath = .SelectedItems(1)
        End If
      End With
      HyperSource = StrPath
End Sub

Code:

Private Sub CancelButton_Click()
Unload Me
UserForm1.Hide
End Sub

Attached Files

Condensing code from a recorded macro

$
0
0
Hi All

I'm attempting to condense the code from a recorded macro. I thought I could just add arrays, but it's not working. Can someone please point me in the right direction?

The first code is the recorded macro and the second code is my unsuccessful attempt at condensing.
Viewing all 49987 articles
Browse latest View live