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

Delete Current Line in word using Excel VBA

$
0
0
Hi,

I am trying to delete whole line where my cursos is from VBA from Excel but in Word Document.
Do you have any idea how to solve this ?

Best regards,
Jacek

Select PivotItems from to...

$
0
0
Hi everyone!

I have an pivottable with pivofields ("Year").

Via a UserForm I chose the desired period using 2 Comboboxes: Combobox1 (from) and Combobox2 (to).

Depending on the selected period, e.g. from 2011 to 2013, i want to select all of the years in the pivot table in that period (2011, 2012, 2013).

I came up with a code, it makes something, but not that what i want... Right now the code selects the pivoitems 2,3,4 (but manually, with fix values in the code) but i want it to select them depending on the variable in the combobox.

Sub pivot_item_jahr()

Dim oPI As PivotItem
Dim i As Integer
For Each oPI In ActiveSheet.PivotTables("PivotTable2").PivotFields("Year").PivotItems
For i = 2 To 4
ActiveSheet.PivotTables("PivotTable2").PivotFields("Year").PivotItems(i).Vi sible = True
Next i
oPI.Visible = False
Next oPI
End Sub

Thanks a lot for any help!

Using a pasted list into a userform textbox as the source for a VBA loop against a Master

$
0
0
I have a list of customer numbers which when checked by Quality Control need to be marked as compelte and the batch number.

I am thinking of creating a textbox with the multiline option set to allow multiple lines so a list can be pasted into the box and when they press the command button the macro loops through each of the lines in the list and checks it's presence against the main master list.

There will be two other text boxes the batch and date can be set within and I will use an row offset to set the cell values for this part.
It is just the loop part that I am struggling to formulate and structure in my mind.

I'm wondering if this is the best approach for something like this. If so can anyone suggest a code construct rather than giving me the code so I can try tio piece this together?

If I fail miserably I may come back looking for specific code help but for now a direction and high level guidance would be appreciated

Thanks

Combining Find With =MONTH(NOW())&"/1/16"

$
0
0
Hi all.

I'm a little stumped on this problem. I have a data dump that I update automatically via power query just after midnight and email the results to our management team. It's a Godsend and means I can actually spend my time analysing results rather than pulling them. Only thing is, a refresh of the data is required from the start of the month, so I currently use the following code to cleanse my data dump first:

ActiveWorkbook.Worksheets("Data Dump").Columns(1).Find("9/1/16").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete

This works a treat, but I will always have to hard code the VBA each time a new month kicks in. Is there any way to adapt the formula to use the Now() function to ensure the date is always correct?

Any help is much appreciated as this one has me stumped!

Regards,

James

Activating an Image in a User Form

$
0
0
Hi,

Can anyone offer any assistance. I have a userform and I wish Combobox 1 to perform two actions.
One to select a bracket whose dimension populates a box and also to fill an image box with the actual image
to prevent errors in production. I can get this to work with combo box 2 but need a specific command for combobox1?

I need a command that tells the combo box to perform two functions:

Code:

Private Sub ComboBox1_Change()
    Dim dWidth As Double
    dWidth = GetWidth(Me.ComboBox1.Value)
    Me.TextBox2.Value = Format(dWidth, "0""  """)
    Me.TextBox3.Value = Format(Abs(Me.TextBox1.Value - dWidth - 10), "0""  """)
   
    If IsNumeric(Me.TextBox3.Value) And IsNumeric(Me.TextBox4.Value) And IsNumeric(Me.TextBox5.Value) Then
    Me.TextBox6.Value = (Val(Me.TextBox5.Value) - Val(Me.TextBox3.Value)) + Val(Me.TextBox4.Value)
Else
    MsgBox ("You must have numerical values in Textboxes 3, 4, and 5")

End If


    Image1.Picture = LoadPicture("\\MAESTEGSVR2\Data\Common Folders\Technical & QA\CAD\Images for labels\" & ComboBox1)


End Sub

VLOOKUP for Rows from Multiple Sheet Macro

$
0
0
Hi!
I am working on another workbook and hoping to find help on VLOOKUP for multiple Sheets.
On Sheet "Main Sheet" starting from Row 10, I have a table from "B" all the way to "U".
My goal is to Populate Columns J to U based on the VLOOKUP value from Column D.
The Lookup data will be from different sheets (12 of them).
The Lookup Column is C and the value I need to get is from Column AA.

I have attached the sample workbook and hope you can help me with a Macro.
I'd like the results (in J to U) to be in Value rather than formulas.

Thank you and appreciate any help I can get.
Cheers.
Attached Files

How to write a formula that pulls in another string of formula from another cell

$
0
0
Hi guys

I've been banging my head against a brick wall for the last 24 hours trying to figure out how to do this using the forum, google and youtube but no luck

I suspect I need to use the INDIRECT formula but not sure

Basically I have the formula
Formula:
=VLOOKUP(B$2,'C:\[Coin order WK30.xls]Sheet1'!$B$6:$K$39,10,FALSE)


What I want to do is have the "WK30" linked from another cell which contains the text "WK30"

Every week I will then copy down the VLOOKUP and in column A where the text "WK31" is for example, the formula will then process as
Formula:
=VLOOKUP(B$2,'C:\[Coin order WK31.xls]Sheet1'!$B$6:$K$39,10,FALSE)


Once this is done then each new row copied down will pull in the data from the latest week's spreadsheet I would of saved as "C:\[Coin order WK31.xls" before performing the VLOOKUP copy down mentioned above

Anyone got any ideas??

I did use
Formula:
=VLOOKUP(B$2,'C:\[Coin order "A31".xls]Sheet1'!$B$6:$K$39,10,FALSE)
but it doesn't work. Just returns "0" or yesterday when I was fiddling, "#ref"...


If anyone can help i will be eternally grateful

Coding/Formatting Dates in VBA to use in SQL

$
0
0
I hope this is the right forum for my problem.
I am trying to write VBA code to run a MS-query on an ODBC link to our accounting package. (Sage Line 100)
Code:

Sub ODBCLink(SheetName, TopVal)
Dim STO1 As Long
Dim FROM1 As Long


        With Sheets(SheetName)
        .Range("C:K").Clear
        End With

            With Sheets("UTILITIES")
                STO1 = .Range("D4").Value
                FROM1 = .Range("B4").Value                                                        ' parameter value
            End With
                SFROM2 = Format(CDate(FROM1), "yyyy/mm/dd")                        ' to achieve date format used by ODBC
                    Const SAGECONN = "ODBC; DSN=WindmillSage;UID=test;; "
                Dim rngTape As Range
            Dim qtTAPEO As QueryTable
          Dim strSQL  As String

  strSQL = BuildSQL(SFROM2)
    Set rngTape = Sheets("DownLoad").Range("C3")
      Set qtTAPEO = Sheets("DownLoad").QueryTables.Add(SAGECONN, rngTape, strSQL)
        qtTAPEO.RefreshStyle = xlOverwriteCells
    qtTAPEO.Refresh False
  qtTAPEO.Delete
End Sub
Function BuildSQL(SFROM2)
1 Sqlstring = "SELECT SALES_LEDGER.ACCOUNT_NUMBER, SALES_TRANSACTIONS.GOODS_AMOUNT "                                                                                          ' This line
2  Sqlstring = Sqlstring & "FROM ACCOUNTING_SYSTEM.SALES_LEDGER SALES_LEDGER, ACCOUNTING_SYSTEM.SALES_TRANSACTIONS SALES_TRANSACTIONS "    'Plus this line
3    Sqlstring = Sqlstring & "WHERE SALES_LEDGER.THIS_RECORD = SALES_TRANSACTIONS.PARENT_RECORD "                                                                              'plus this line                                                                         
4  Sqlstring = Sqlstring & "AND ((SALES_TRANSACTIONS.TRANSACTION_TYPE=4 Or SALES_TRANSACTIONS.TRANSACTION_TYPE=5) "                                            ' plus this line  all work together adjusting brackets
5  Sqlstring = Sqlstring & "AND (SALES_TRANSACTIONS.TRANSACTION_DATE >{d'SFROM2'}))"                                                                                            ' This line gives error
  BuildSQL = Sqlstring
End Function

This code works using lines 1 to 4 in BuildSQL as long as I adjust the AND and OR brackets
but if I add line 5 I get "General ODBC Error message. I am fairly sure that it must be the date coding which is wrong.
Also despite the line gtTAPEO.Delete I get a build up of separate Connections in the Data/ Connections list each time I run the Sub routine. How can I stop this?
I hope somebody can guide me on this
John

Help with Vba code please

$
0
0
Hi, I would appreciate any help with this code please
What I want is help with this code in VBA

(1) ask for row number
(2) copy down to end "A" col to "E" column from that row
(3) copy to row above

Not move as it disturbs formulas in columns F:K

here is the code I wrote but it fails

[CODE][CODE] rn = InputBox("Enter the row number you want to delete...", "Row number please")

If rn = "" Then
MsgBox "Please enter the row number you want to delete", vbOKOnly, "Row number required"
Exit Sub
End If

If rn = 3 Then
MsgBox "You cannot delete any row above Row 4", vbCritical, "Stop"
Exit Sub
End If

Application.CutCopyMode = True
Range("A" & rn)."A":"E".Select

any help will be appreciated
Graham

checking value in cell and then pasting to a specific worksheet

$
0
0
hi,


so here's what I'm attempting to do is to, I need to check a cell to see if the first two characters in that cell match one of three things. once I have checked that I then need to copy that range of cells and then paste it into a specific worksheet. I have been told use InStr and if's to do it but Im struggling to code it. I understand how to copy paste data from one sheet to another but its the checking part im not 100% sure of can anyone help?

VBA code to move data up one row

$
0
0
Hi Experts, please help with my problem
I need to ask for a row number
from that row number copy down from A:E data
move that up one row
I have formulas in columns F:K, so I hope that code wont affect the formulas

Hope you can help
Graham

[SOLVED] trigger a macro / Clock

$
0
0
Hi, i have to run a file (constant) on the bloomberg machine, which should trigger a macro (import/export figures) 4 days in a week at 12.00 pm bla bla

The clock runs fine, and i get the message i want, but i want the clock going further with counting (it stop after giving the message)

Solved it myself pff that easy.

[/CODE]
Sub SetTime()

If ThisWorkbook.Sheets("Sheet1").Cells(4, 10).Value >= 3 Then
MsgBox ("hell yea, it works perfectly"), vbInformation
SchedRecalc = Now + TimeValue("00:00:01")
'herhaling
Application.OnTime SchedRecalc, "Recalc
"

Else
'+1 seconden
SchedRecalc = Now + TimeValue("00:00:01")
'herhaling
Application.OnTime SchedRecalc, "Recalc"

End If

VBA Excel - Adding a therm on a formula already exist in a cell.

$
0
0
Hi guys, my question is simples. I have this code, running just fine, but now I need to add something in it.


Code:

Set b = .Range("D" & First2, "D" & Last2 + QtP)For Each cell2 In b
If cell2.Interior.ColorIndex <> xlNone Then
    .Range("D4").Value = "=" & cell2.Address
End If
Next cell2

As you can see, he searches which cell it's colored and then reference in the Cell "D4". But I need sum one cell (always fixed coordenates), so that in the cell something like: "=R$4 + T$11". R$4 just example, that my code is already finding, and I need to add the cell T11.

I tried a few variations but I can't get through.

Code:
Code:

.Range("E4").Value = "=" & cell2.Offset(0, 1).Address + T$11"
.Range("E4").Value = "='" & cell2.Offset(0, 1).Address + "'T$11"
.Range("E4").Value = "=" & cell2.Offset(0, 1).Address + .Range("T11").Address"



thanks in advance.

Frames & Option buttons on form

$
0
0
Hi.

I've created a form, that I want to transfer the data from the form to an excel data sheet as a record entry. The form consists of 41 frames, and inside each frame is 4 option buttons labelled "Strongly Agree, Agree, Disagree, Strongly Disagree". How do it do something like frame1.value and show whatever radio button has been selected in frame 1, and provide the labelling that the option button has as the text to transfer into excel.

data analysis between 2 workbooks

$
0
0
Hey everyone,

My manager asked me to simplify his life, I am design engineer and during projects we are exporting data in excel form, multiple times during the life of project.

And there is a problem, is there a way how to do data analysis between two workbooks? Basically I want that book1.xlsx is compared to book2.xlsx, and the book1.xlsx after comparison would look like book3.xlsx. Changes would be colored.

The thing I would like to have that File A from book1 would loop through the book2 and look for the changes in quantity , and the quantity from file A from book2 would appear in column C of book1 and if is changed it would be colored; and the do the same for file B and so on, so on.
And if new files have appeared in book2, it would appear at the bottom of page at book1.

I have attached example files, and hopefully I explained myself.

I will be grateful if someone could help me!

Matiiss
Attached Files

Find

VBA Macro Dividing Values Based upon Matching Criteria and Description Criteria

$
0
0
Dear Experts,

It is different concept,

*Read one cell values and One entire Column (Ex:AH2 and X column)

*If Same Value coincide, extract that value to another Cell for sort out order by Description (Ex: Extract X column Value to AH6 Cell)

*So Values are Divided by Matching Criteria and Description basis.

Please find the sample file for more clarity and kindly provide suitable code.


Thanking you All,
Best Regards.
Attached Files

VBA for Autofilter linked with combo box

$
0
0
Hi

i have tried to link the two tables with a combo box. But vba is not working. Please help me.


Sub Macro8()

Sheets("BankBook").Select
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Operator:= _
xlFilterValues, Criteria2:=Array(2, "h1")
Sheets("CashBook").Select
ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=1, Operator:= _
xlFilterValues, Criteria2:=Array(2, "h1")
End Sub
Attached Files

Reverse Data - Find data and return result in a new table

$
0
0
Hello All.

This is my first post so I am not sure of whether or not this has been answered or not or whether this is the right section for this question. I have searched forums but I was not sure exactly how to define the problem to get the desired results.
My problem is that I would like to take data from one log and create a new log with the same information only reversed. I have two columns I need to switch in order to get the desired result and was thinking that there must be a macro capable of doing this.
There are over 3,000 items to go through and it is not quite as simple as outlined below (obviously).

EXAMPLE:
<
>

<
>


Let me know if this is clear enough or if more information is needed to assess the situation.

Any help is much appreciated!

Activate a custom Ribbon

$
0
0
Hi,

I am triying to activate a custom ribbon when an xlm file is opened
I have tried .ActivateTab ("Demo_Home") (in the joined XLM file) but it does not work.

Any idea ?

Tx
Attached Files
Viewing all 50243 articles
Browse latest View live