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

Removing items from cart

$
0
0
Hey Guys,

I'm trying to build a code that will remove all the items in my cart at Overstock.com.

There are Remove buttons under each item, but I can't seem to figure out how to click them with VB.

I have code that determines how many items are actually in the cart, so I was hoping there'd be a way to just loop through and click all the Remove buttons.

Looping through the code below, and multiple other attempts, doesn't do anything. So I'm struggling to come up with the correct element designation.

Code:

ObjIE.document.getElementsbyClassName("cart-edit-options").GetElementsByTagName("a").Click
Thanks!!

how to solve if the sheet contain too many shape or control?

$
0
0
Hi All,

I have a workbook which contain a sheet that have many shape or control.
When you select the sheet, you need to wait a long time such as 10 sec.
I try the below code to remove the shape. but it is failed when invlove "activesheet".
I can't use sheets("hehe").activate. the error msg is automation error. element not found.
I don't understand why it will happened. The file don't have any vba code.

I uploaded the file here.
http://khchan.byethost18.com/sheet_cant_active.xlsx
Code:

Sub killShape()
    For Each ID In ActiveSheet.Shapes
        If Left(ID.Name, 7) = "Control" Then
            ID.Delete
        End If
    Next
End Sub

Disregard

[SOLVED] Loop Solver using VBA

$
0
0
Hello,
I have a solver query where I want to maximize the value in cell E2, while in cells B2:D2 there is a formula that is reliant on the value in E2 (plus some other fixed values that are presented in the worksheet). I need each of these cells (B2:D2) to fit within constraints specified within the workbook. I can perform this easily enough using the solver function, but I have multiple rows of data, so I would like a macro that maximises the value in E2, and then moves on to the next value (E3) and solves that cell, and before moving onto the next row until all rows have been solved.

I have attached a spreadsheet where I have manually used the solver function (you can see the solver in the data tab) the maximal value for E2, E3 and E4, but I would like a vba script that would automatically solve the remaining rows without having to go into the solver and change the target and constraint cells.

Solver.xlsx

Any assistance here would be greatly appreciated.

T15K

Find time difference (working hours) on first SwipeIn and last SwipeOut

$
0
0
Hello Friends.

I have a huge data of employee swipe in and out time with a pivot drawn on it. I am having difficulties whenever an employee swipes attendance twice on the same day. The data output is little jumbled. Sometimes it shows earliest In-Time and latest Out-Time in the corresponding column next to each other and sometimes it is upside down hence I am unable to think of a logic as to how to accomplish this. I want to keep the earlier In-Time and remove the latest one and similarly, keep the latest Out-Time and remove the earlier one. Whenever there is only one time available, it has to be considered as In-Time. The Worked Hours column needs to be updated with time difference (if both the valid times are available), One Swipe if there is only one swipe time available and No Swipe if there are no swipe times available for a particular date.

File attached for your reference. Kindly suggest a code to remove unwanted rows or if there is any formula based solution.

Thanks
Attached Files

Application.WorksheetFunction functions shortcut

$
0
0
I use some of the Excel Worksheet Functions a lot in my code e.g. Application.WorksheetFunction.Round(), Application.WorksheetFunction.RoundUp(), Application.WorksheetFunction.RoundDown() etc.

In my code I then make a shortcut function e.g. MyRound() which takes the same arguments and then use the Excel function to return my rounded value.
Code:

Public Function MyRound(ByVal nValue As Double, ByVal nDecimals As Double) As Double
MyRound = Application.WorksheetFunction.Round(nValue, nDecimals)
End Function

Saves me from typing Application.WorksheetFunction.Round() every time. When I need the function it's much faster typing MyRound().

This works with functions that has a set number of arguments.

My problem is how would I do this with a function that has a bunch of arguments (optional arguments?) e.g. Max() or Min(). The Excel versions of these functions can take up to 30 arguments. How would I declare MyMax() or MyMin() with these optional arguments?

I tried
Code:

Public Function MyMin(Arg1 As Double, Optional Arg2 As Double, _
    Optional Arg3 As Double, Optional Arg4 As Double, Optional Arg5 As Double, _
    Optional Arg6 As Double, Optional Arg7 As Double, Optional Arg8 As Double, _
    Optional Arg9 As Double, Optional Arg10 As Double, Optional Arg11 As Double, _
    Optional Arg12 As Double, Optional Arg13 As Double, Optional Arg14 As Double, _
    Optional Arg15 As Double, Optional Arg16 As Double, Optional Arg17 As Double, _
    Optional Arg18 As Double, Optional Arg19 As Double, Optional Arg20 As Double) As Double
   
    MyMin = Application.WorksheetFunction.Min(Arg1, Arg2, Arg3, Arg4, Arg5, _
        Arg6, Arg7, Arg8, Arg9, Arg10, Arg11, Arg12, Arg13, Arg14, Arg15, _
        Arg16, Arg17, Arg18, Arg19, Arg20)
End Function

This doesn't work though. Calling MyMin(1,10,100) returns 0? Similarly calling MyMax(-1, -10, -100) will return 0? It seems the arguments that are omitted is defaulted to 0 and thus 0 is returned in these cases.

vba code to distribute account to team members

$
0
0
Hi All,

Request you to please help me!

I want a vba code to distribute account to team members I have created a userform in userform I have a list of team members and check boxes in front of names when I select names selecting check boxes and enter
The number in combobox like 5 then each name should paste 5 times in the D column of the sheet agent file.

Please find the attached sample file.

Regards

Xlhelp7
Attached Files

Default Runtime error 13 type mismatch in Excel VBA

$
0
0
I have started getting - runtime error 13 type mismatch. The error is coming on Selection.Formula line. Need help how to fix it.

The code is:
Code:

L = InputBox("Minimum")
H = InputBox("Maximum")
Range("B1").Offset(R, C).Name = "RandDataRange"
Range("B2", Range("RandDataRange")).Select
Selection.Formula = "=ROUND((" + L + ") + (" + H + " - " + L + ")*RAND(),0)"


Month Name in English

$
0
0
Dear all

I am using the following line of code to extract the month range from a value in a cell
Code:

monthname(right(Range("I7").value,2))
However, VBA by default uses the regional settings - how would I get the English Name in VBA?

Thanks
FD

Cell Will Not Keep It Formatting

$
0
0
Further to a previous post, Im adding two paragraphs of text to a cell. I only want the first two words "Product Description" to show, unless the cell is clicked and then you see all the text

I have managed to do this by fixing the "Height" of the row and removing "Text Wrap"

This works and when you click the cell the text reads across the page.

However, if you click the cell a second or further times the text flows downwards in the column instead of across almost like the formatting only works once

Many kind thanks

Need improve macro speed

$
0
0
[CODE]Attachment 437247
Here is the file. E2:J2 and E7:J7 can be empthy (sry, can remove and reattach file from my device).

And the macro for it. Need optimization. Macro works slowly if 300K+ rows

Code:

Option Explicit

Sub SetData()

    Dim r&, j&, maxValue#, maxValuePos&, last_row&, lRow&
    Dim sCriteria$
    Dim rngTable As Range, rngData As Range, rngVisible As Range
    Dim rngRow As Range, rngArea As Range
    Dim arrPos(), arrValues()
   
    '// MsgBox TypeName(maxValuePos)
    Application.ScreenUpdating = False
   
    ActiveSheet.AutoFilterMode = False '//Remove the filter.
    last_row = Cells(Rows.Count, "A").End(xlUp).Row '//Determine the last row of the column "A".
    Set rngTable = Range("A1:K" & last_row) '//Full range of the table. (With the headline!)
    With rngTable
        Set rngData = .Offset(1).Resize(.Rows.Count - 1) '//Range table without a title - is required for the AutoFilter.
    End With
   
    '// As we are interested only rows "non Type 1", , for optimization
    '// we filter once a column D (serial number 4 concerning the filter) on this value
    rngTable.AutoFilter Field:=4, Criteria1:="<>Type 1"
   
    For r = 2 To last_row '//pass on every row. Stealthiness of rows (look the above row) doesn't influence it.
       
        If Cells(r, "D").Value = "Type 1" Then '//Find rows with "Type 1"
            sCriteria = Cells(r, "C").Value '//Criteria
            rngTable.AutoFilter Field:=3, Criteria1:=sCriteria '//Filter by criteria

            On Error Resume Next
            '// We are interested in visible cells.
            '// Catching of mistakes is necessary if value isn't found (that is the empty filter)
            Set rngVisible = rngData.SpecialCells(xlCellTypeVisible)
            If Err = 0 Then '//All OK. Filteres rows is here
                j = 0 '//Keeps quantity of positions in the massif
                Erase arrPos: Erase arrValues '//Clear the massif
                For Each rngArea In rngVisible.Areas '//As untied ranges, we use Areas...
                    For Each rngRow In rngArea.Rows '// ...and already in Areas there are our lines
                        j = j + 1
                        ReDim Preserve arrPos(1 To j): arrPos(j) = rngRow.Row '//We write down a row number
                        ReDim Preserve arrValues(1 To j): arrValues(j) = rngRow.Cells(11).Value '//We write down value
                    Next
                Next
                maxValue = WorksheetFunction.Max(arrValues) '//Max value
                maxValuePos = WorksheetFunction.Match(maxValue, arrValues, 0) '//Row number with the maximum value
                lRow = arrPos(maxValuePos) '//Row of the worksheet
                '// We copy values from a row with the maximum value in ours
                Range(Cells(r, "E"), Cells(r, "J")).Value = Range(Cells(lRow, "E"), Cells(lRow, "J")).Value
            Else
                '// It is filtered nothing - we fill with hyphens
                Range(Cells(r, "E"), Cells(r, "J")).Value = "-"
            End If
            On Error GoTo 0
        End If
       
    Next

    rngTable.AutoFilter 'Remove filter
    MsgBox "Done!", vbInformation
   

End Sub

Moving Rows based on cell content

$
0
0
The code below will move rows where column E contains "43A" to sheet EE. I have a couple of questions.

1. How can I concatenate E and G to make their criteria together to move to EE?
2. If I have other combos to move to other sheets beside EE can I recopy the code below the loop line and modify criteria?


Code:


Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+m
'
Set i = ActiveSheet
Set e = Sheets("EE")
Dim d
Dim j
d = 1
j = 2

Do Until IsEmpty(i.Range("E" & j))

If i.Range("E" & j) = "43A" Then
d = d + 1
e.Rows(d).Value = i.Rows(j).Value

End If
j = j + 1
Loop

End Sub

Send emails to different people each containing different content in the body based on cel

$
0
0
Hello all,

I am still very new to VBA, and the Mail function is confusing me to no end. What I'm trying to do is to send a list of emails to emails listed in column A (A1-A30) each containing different information in the body of the email based on whats in other cells (or sheets in the workbook)

so I want to send an email to the address listed in A1 containing, in the body of the email, content from cells B1-E1.

and repeat for subsequent cells.

The email program I will be using is outlook 2010, but is it possible to direct emails to pop up using whatever the default windows email client is for that computer?

Any help is really appreciated!

thanks a ton,
Drake

Macro to create multiple checkbox cell links on second sheet

$
0
0
Hi there.

I have approx 800 rows with checkboxes in columns C through I on Sheet1, although some rows have no checkboxes. Currently the checkboxes have no cell links assigned. I would like some help with writing a macro that assigns a cell link reference for each checkbox, but in a second worksheet.i.e the checkbox in C1 Sheet1 will end up with cell link "Sheet2!$C$1" etc. The checkboxes are already created.

I found a useful starting point for the macro in this post http://www.excelforum.com/excel-gene...check-box.html although this is a single column solution.

Thanks in advance.

Need to add timestamp and user stamp to worksheet

$
0
0
Hello,

I am new to the VBA stuff and need to add a date stamp to A2, and a Name stamp to M2 and timestamp to N2 when something is entered into B2-L2.

To add a little complexity I am using a Excel Form to add the information to the worksheet.

Can anyone help? I have added the file for reference. The tab is "Data"

Thanks!!
Attached Files

Problem with writing an output to a word File from Excel Userform

$
0
0
Hello everyone and happy holidays if you celebrate,

I am finally trying to retool one of my old userforms, because the old one had become painfully slow (because I was an idiot). It appears that I have one last thing to fix that has been bothering me. I am trying to save my output from a contact logger form to an archive file that is a word document. It opens the file, pastes the output from the contact logger to the word file, saves the word file, and then closes it. Most of the time, it works very well. The only stumbling block for me is if I goof up, and have the file open. The code below was mostly copied from the web of course. I was thinking that moving the "open the file" part up into the error handler would be something to try, but was at a loss for how to set the file to active if it was already open.

Code:

Private Sub WordOutput(Output As String)

  Dim objWord

  Dim objDoc

  Dim objSelection

  Dim END_OF_STORY

    Dim MOVE_SELECTION

  END_OF_STORY = 6

    MOVE_SELECTION = 0
   
    'We need to continue through errors since if Word isn't
    'open the GetObject line will give an error
    On Error Resume Next
    Set objWord = GetObject(, "Word.Application")

    'We've tried to get Word but if it's nothing then it isn't open
    If objWord Is Nothing Then
        Set objWord = CreateObject("Word.Application")
    End If

    'It's good practice to reset error warnings
    On Error GoTo 0

  Set objWord = CreateObject("Word.Application")

  Set objDoc = objWord.Documents.Open("C:\OneStopArchive.docx")

  objWord.Visible = True

  Set objSelection = objWord.Selection

  objSelection.Font.Bold = False

  objSelection.EndKey END_OF_STORY, MOVE_SELECTION

  objSelection.Font.Size = "14"

  objSelection.TypeText (Now & vbCrLf & Output & vbCrLf & vbCrLf)

 objDoc.SaveAs ("C:\OneStopArchive.docx")
 
 objWord.Quit
 Set objWord = Nothing

End Sub

Any help would be appreciated. :)

BobR

sort top n% in each column and identify rows that are in top n% in three consecutive colum

$
0
0
Hi,

I have a large data set with over 10000 sales records. I would like to identify the top n% of performers in each month and then identify whether these performers were in the top n% in three consecutive months. Those names need to be stored on a different sheet. Could you help me with a VBA script that can take care of this?


Thanks

If Cell A contains Value Cell B must be enter.

$
0
0
Hi

I have an excel sheet where I want to bound the user if the cell A1 have an specific value than B1 must not be blank. B! should have the value.

E.g.
If cell A1 have "Xy" or "YZ" user must enter the value in cell B1.
if there is any other value user can leave the cell blank.


Please help

Problem with arrays using an interval and including numbers at specific locations

$
0
0
Hello all,

I have a problem with the following:

I have multiple columns of numbers, which are sorted in ascending order and can be of variable length and interval, but always start at 0.
For this problem, I have selected 4 columns though.

0.00 0.0000 0.0000 0.0000
0.25 0.3025 0.1600 0.2025
0.50 0.6050 0.3200 0.4050
0.75 0.9075 0.4800 0.6075
1.00 1.2100 0.6400 0.8100
1.25 1.5125 0.8000 1.0125
1.50 1.8150 0.9600 1.2150
1.75 2.1175 1.1200 1.4175
2.00 2.4200 1.2800 1.6200
2.25 2.7225 1.4400 1.8225
2.50 3.0250 1.6000 2.0250
2.75 3.3275 1.7600 2.2275
3.00 3.6300 1.9200 2.4300
3.25 3.9325 2.0800 2.6325
3.50 4.2350 2.2400 2.8350
3.75 4.5375 2.4000 3.0375
4.00 4.8400 2.5600 3.2400
4.25 5.1425 2.7200 3.4425
4.50 5.4450 2.8800 3.6450
4.75 5.7475 3.0400 3.8475
5.00 6.0500 3.2000 4.0500
5.25 6.3525 3.3600 4.2525
5.50 6.6550 3.5200 4.4550
5.75 6.9575 3.6800 4.6575
6.00 7.2600 3.8400 4.8600
6.25 7.5625 4.0000 5.0625
6.50 7.8650 4.1600 5.2650
6.75 8.1675 4.3200 5.4675
7.00 4.4800 5.6700
7.25 4.6400 5.8725
4.8000
4.9600
5.1200
5.2800
5.4400

Each column has a certain number, which is important to other calculations. This number can be everywhere in each column, but for ease of reference I selected 4 random numbers (bold).

Starting with the first column, the maximum value is determined via VBA (in this case 7.25). Using a user defined interval number (in this case 0.3), a new column is created which starts at 0 and adds 0.3 for each row until the maximum value of 7.25 has been reached.

However, the bold number is of importance too. So this value is to be included in the newly created column. So 3.25 in column 1 is to be included between 3.00 and 3.30 (see below)

0.00
0.30
0.60
0.90
1.20
1.50
1.80
2.10
2.40
2.70
3.00
3.25
3.30
3.60
3.90
4.20
4.50
4.80
5.10
5.40
5.70
6.00
6.30
6.60
6.90
7.20

After the first column, the other colums will get new intervals in a similar fashion as presented above. However, there will also be a fixed value added to each newly created row (interval), based on the value in the previous column. In this case 0.2, so the bold/underlined values will need to be included also.

0.00 0.20 0.40 0.60
0.30 0.50 0.70 0.90
0.60 0.80 1.00 1.20
0.90 1.10 1.30 1.50
1.20 1.40 1.60 1.80
1.50 1.70 1.90 2.025
1.80 2.00 1.92 2.10
2.10 2.30 2.20 2.40
2.40 2.42 2.50 2.70
2.70 2.60 2.80 3.00
3.00 2.90 3.10 3.30
3.25 3.20 3.40 3.60
3.30 3.50 3.70 3.90
3.60 3.80 4.00 4.20
3.90 4.10 4.30 4.50
4.20 4.40 4.60 4.80
4.50 4.70 4.90 5.10
4.80 5.00 5.20 5.40
5.10 5.30 5.70
5.40 5.60
5.70 5.90
6.00 6.20
6.30 6.50
6.60 6.80
6.90 7.10
7.20 7.40
7.70
8.00

However, the above table is incorrect and this is where my problem comes into play. Every time the bold value of the applicable column is inserted, the table needs to get a new line and the preceding and following columns need to get a new value, based on the bold value of the applicable column and user defined interval (0.2 as example). The table below shows the result, the underlined values are the original values of the applicable column, which need to be included and the bold values are a result of this underlined value.

0.00 0.20 0.40 0.60
0.30 0.50 0.70 0.90
0.60 0.80 1.00 1.20
0.90 1.10 1.30 1.50
1.20 1.40 1.60 1.80
1.425 1.625 1.825 2.025
1.50 1.70 1.90 2.10
1.52 1.72 1.92 2.12
1.80 2.00 2.20 2.40
2.10 2.30 2.50 2.70
2.12 2.42 2.62 2.82
2.40 2.60 2.80 3.00
2.70 2.90 3.10 3.30
3.00 3.20 3.40 3.60
3.25 3.45 3.65 3.85
3.30 3.50 3.70 3.90
3.60 3.80 4.00 4.20
3.90 4.10 4.30 4.50
4.20 4.40 4.60 4.80
4.50 4.70 4.90 5.10
4.80 5.00 5.20 5.40
5.10 5.30 5.70
5.40 5.60
5.70 5.90
6.00 6.20
6.30 6.50
6.60 6.80
6.90 7.10
7.20 7.40
7.70
8.00

Can anyone help me with this problem? I am looking for a VBA solution for this problem.

Many thanks in advance,
Martin

Provide total items + amounts when compile data in multiple worksheet

$
0
0
I have been seeking days trying to play with formulas, then play with count/sum by using colour format and now it really messy and it does not seem to be fully working.

I have 3 different worksheets called Report 1, 2 and 3 that I need to import data everyday. Data could range from 0 to over 125 traders. It starts from Row 14.

If you check the file, Report 1 = 5 traders, Report 2 = 0, Report 3 = 13 traders

In the worksheet, I put the number of items manually, so I would like to add a macro that once the data is loaded into excel (like the attachment), I will run that macro so...

1. it will count and provide the number of items in EVERY worksheet.
The total of items should be added 2 rows below the last item (to leave one row space).

2. It will sum the total and input it into D4 from its respective Sheet.
If there is no trade that day (like Sheet2), then D4 will be "0" and it will skip the input of total items.

3. It will count the total of items in all Sheet and input it into H5 (Sheet 1).

Sheet 2 and 3 net total is referred to sheet 1.

Really appreciate if anyone can help me figure out this thing.

Reports XYZ.xlsm
Viewing all 49892 articles
Browse latest View live