Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all 88178 articles
Browse latest View live

Error Occurred "Type Mismatch" whenever my macro Loop through Column A and return more than 15 match string

$
0
0

Currently I am facing an issue whenever my macro loop in through Column A to search the string "Country Code:" and it return the matched string more then 15 times . An error "Type Mismatch" would occurred. I have search through online but I could not find the solution and hope that you guys would give me an insight on what should i do

I have checked and compare my string with the raw data and it shown that there is no spelling mistake whatsoever. But i have noticed if i insert a small amount of data where the macro would return around 7 result there would be no issue.

Below is my code. I apologize for my code as i am still learning and I follow this sample online

Sub testCountryCode()
Dim ws As Worksheet
Dim toWs As Worksheet
Dim vDB, vR()
Dim i As Long, n As Long, c As Integer
Dim j As Integer

Set ws = Sheets("Database")
Set toWs = Sheets("CMF")

vDB = ws.UsedRange
c = UBound(vDB, 2)
For i = 1 To UBound(vDB, 1)
    If InStr(vDB(i, 1), "Country Code:") Then
        n = n + 1
        ReDim Preserve vR(1 To c, 1 To n)
        For j = 1 To c
            vR(j, n) = vDB(i, j)
        Next j
    End If
Next i
toWs.Range("a2").Resize(n, c) = WorksheetFunction.Transpose(vR)
Sheets("Result").Select

End Sub

ActiveX error in VBA code to replace words in a Powerpoint

$
0
0

I have a VBA code which is supposed to replace a word by another in a powerpoint. Nevertheless, when I try to run it I get the error 429 "ActiveX component can't create object" but I do not know why. Here is the code :

Sub pres()

    Dim PowerPointApp As Object
    Set PowerPointApp = CreateObject("PowerPoint.Application")

    Dim myPres As Object
    Set myPres = PowerPointApp.Presentations.Open("C:\Users\NAME\Desktop\PRESVBA\Pres.pptx")

    Dim sld As Slide
    Set sld = ActivePresentation.Slides(3)
    Dim shp As Shape

    For Each shp In sld.Shapes
    If shp.HasTextFrame Then
        If shp.TextFrame.HasText Then
            shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Montant", "Amount")
     End If
    End If
    Next shp
End Sub

Grails: Excel exporting .xlsx style issues, error message when opening the file

$
0
0

I'm using grails-excel-export plugin to export data into an Excel (in xlsx format), but I'm having issues when opening the file with Microsoft Office (no problems with OpenOffice).

When I open it, I get the message "We found a problem with some of the content in 'exportedFile.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes", same as this one:

enter image description here

I've already found out that the problem comes only when applying any kind of cellstyle to the workbook, in my case I'm to set bold the first row.

This is the code:

def exportToExcel(results, headers, properties, ByteArrayOutputStream outputStream) {

    WebXlsxExporter webXlsxExporter = new WebXlsxExporter()
    webXlsxExporter.setWorksheetName("Sheet")
    webXlsxExporter.with {
        fillHeader(headers)
        add(results, properties)
        save(outputStream)
    }

    def wb = webXlsxExporter.getWorkbook()
    def row = webXlsxExporter.getSheet().getRow(0)
    makeFirstRowBold(wb, row)

    wb.write(outputStream)
}

def makeFirstRowBold(Workbook wb, Row row) {
    CellStyle style = wb.createCellStyle()
    Font font = wb.createFont()
    font.setBold(true) //Already tried with font.setBoldweight(Font.BOLDWEIGHT_BOLD)
    style.setFont(font)

    for (int i = 0; i < row.getLastCellNum(); i++) {
        row.getCell(i).setCellStyle(style)
    }
}

Excel Query to update a Worksheet doesnt keep formats

$
0
0

im trying to update a worksheet, by using queries. Now i have a problem, cause the imported Data keeps getting turned into a table , although the resource Data is not a table.

Basically i want the columns A:E in worksheet(x), to get updated with columns A:E from worksheet(xyz) and keep the formatting from worksheet(xyz).

How can I optimize my web-scraper for 40k+ links

$
0
0

With list of 40k links from which have to scrap emails/company names - takes forever the way I made it.

  1. All websites look the same but they are lacking id's or any proper order/classification. Thus I have to search using regex for the email (or so I think) . For the rest it's easy, them being in the same order/place. In case I use it on a proper website, how could it be faster?

  2. Afterwards, I add everything in a dictionary - because like this if the email repeats, it doesn't append. But then I don't know how to append everything nicely into a excel file. Right now it's split into 2 columns. Would be nice -> each their own column. And I also feel this is sluggish and slow.

  3. Would it be faster to write everything after each find? in case the code breaks. Or it would just extend the time.

  4. The main issue is that there is 1 email - multiple company's and 10x more domains. Is there a way to have rows like this?
    email - company names - domains
    email - company names - domains
from bs4 import BeautifulSoup
import pandas as pd
from openpyxl import load_workbook
import requests
import re
import csv
from datetime import datetime
import time

def details_pag_antillephone(URL, restrans, detalii):
    page = requests.get(URL)
    soup = BeautifulSoup(page.content, 'html.parser')
    results = soup.find('div', class_=restrans)
    detalii = results.find_all('div', class_=detalii)
    return detalii, soup


dataDic = {}
links = []

df = pd.read_excel(r'C:\Users\Adrian\Desktop\40k_links.xlsx')
links = df['Unnamed: 7'].tolist()

start_time = datetime.now()
for i in links[10000:15000]: # Run 5000 intervals, takes too long otherwise
    if i != float:  # sometimes there are floats in the excel file, or empty
        URL = 'http://' + i  # add before to complete the link - to access
        try:   # sometimes there is no email, and otherwise it breaks the code apparently. Workaround? 
            validator = details_pag_antillephone(URL, 'col-md-9', 'flex-row') #col-md-9 is the box containing the text, flex-row contains the company, name, address
            company = validator[0][0].text.strip().split('\n')[1] # always the 1st after split
            address = validator[0][2].text.strip().split('\n')[1] 
            email = re.findall('[\w\.-]+@[\w\.-]+', validator[1].text)[0]
            websites = re.findall('www.[\w\.-]+', validator[1].text)
            dataDic[email] = [company, ''*20, address, websites]
        except:
            continue
end_time = datetime.now()
print('Duration: {}'.format(end_time - start_time))


df = pd.DataFrame(list(dataDic.items()), columns=['Company', 'Detalii'])
print(df)
with pd.ExcelWriter(r'C:\Users\Adrian\Desktop\All_test_1.xlsx') as writer:
    df.to_excel(writer)

Example of what I'm currently working with:

<div class="col-md-9">
            <div class="box">
              <h3>Antillephone License Validation</h3>
              <div class="details subheader">This page was generated on Mar 5, 2020</div>
              <div class="separator"></div>
                <div class="flex-row">
                  <div>Company name</div>
                  <div>Hero Island N.V. </div>
                </div>
                  <div class="separator"></div>
                  <div class="flex-row">
                    <div>Trade name</div>
                    <div>Hero Island N.V. </div>
                  </div>
                <div class="separator"></div>
                <div class="flex-row">
                  <div>Address</div>
                  <div>Curacao, CW</div>
                </div>
                <div class="separator"></div>
                <div class="flex-row">
                  <div>E-mail</div>
                  <div><script>var _0x2a84=['support@casitabi.com'];(function(_0x2ed5df,_0x4a695a){var _0x2f05f3=function(_0x44dc82){while(--_0x44dc82){_0x2ed5df['push'](_0x2ed5df['shift']());}};_0x2f05f3(++_0x4a695a);}(_0x2a84,0x133));var _0x42a8=function(_0x4179b2,_0x957766){_0x4179b2=_0x4179b2-0x0;var _0x2f7fe3=_0x2a84[_0x4179b2];return _0x2f7fe3;};document['write'](_0x42a8('0x0'));</script>support@casitabi.com</div>
                </div>
                <div class="separator"></div>
                <div class="flex-row">
                  <div>Registered Website(s)</div>
                  <div>
                      <a href="//www.simplecasinojp.com"><span>www.simplecasinojp.com</span><br></a>
                      <a href="//www.casitabi.com"><span>www.casitabi.com</span><br></a>
                      <a href="//www.purecasino.com"><span>www.purecasino.com</span><br></a>
                  </div>
                </div>
                <div class="separator" style="margin-bottom: 18px;"></div>

How to convert multiple rows to columns with labels on the first row

$
0
0

I need help to convert multiple rows for a table like below picture 1 to be formatted as the second picture. Is it possible to do this by a formula or what is the easiest way?

I tried using a pivot table but it does not let me format it the way I need.

Pic1

Pic2

XlsxWriter : make a solid filled data bar

$
0
0

I have successfully created some data bar plot with the python module xlsxwriter by its conditional_format method. However, is it possible to specify the fill pattern of condition format within xlswriter or python generally? I tried the following code which didn't work:

myformat = workbook.add_format()
myformat .set_pattern(1)
worksheet.conditional_format(0, 4, 0, 4, {'type': 'data_bar',
                                                  'min_value': 0,
                                                  'min_type': 'num',
                                                  'max_value': 110,
                                                  'max_type': 'num',
                                                  'bar_color': '#C00000',
                                                  'format': myformat})

How to Import multiple XML Files into Excel with VBA without overwriting the files that have already been imported

$
0
0

I have a directory with multiple XML-Files. New XML-Files are added to the directory every day.

I´m trying to import those XML-Files into one specific Excel Sheet everyday, without overwriting the existing data in my Excel Sheet.

I have already managed to import the XML-Files.

Question 1: How can I Import the XML-Files without headings or xml path?

Question 2: Is there a way to only import new data and skip the files I already have imported

Hope anyone can help me out with this. Trying to find a solution for quite a long time and couldn´t find an answer by myself or online.

This is the Structure of my XML-Files:

<MFK_XML xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Auftrag>
    <WarenkorbReferenz>0</WarenkorbReferenz>
    <JobNr>12345-999</JobNr>
    <KuNr>12345</KuNr>
    <ReNr>7</ReNr>
    <SoA>0</SoA>
    <Termin>2020-03-10</Termin>
    <Versandtermin>2020-03-09</Versandtermin>
    <Gewicht>1.1037620</Gewicht>
    <Datencheck>0</Datencheck>
    <Proof>0</Proof>
    <Kundenhinweis />
    <Auflage>5</Auflage>
    <Versionen>1</Versionen>
    <Gesamtpreis>15.50</Gesamtpreis>
    <Priority>S</Priority>
    <ProduktionsTage>5</ProduktionsTage>
    <Mandant />
    <LNr>151</LNr>
    <IVB>10</IVB>
    <Gratis>0</Gratis>
    <Transfer>2020-03-02</Transfer>
  </Auftrag>
  <Artikel>
    <Artikelbezeichnung>Broschüre mit Metall-Spiralbindung, Endformat DIN A4, 48-seitig</Artikelbezeichnung>
    <ArtikelID>12345</ArtikelID>
    <ArtStr>Flex</ArtStr>
    <ProdKrzl>FlX</ProdKrzl>
    <Sorte>135g Innenteil mit 250g Umschlag (matt, hochwertiger Qualitätsdruck, 4/4-farbig)</Sorte>
    <SortenID>152</SortenID>
    <Seitenzahl>48</Seitenzahl>
    <SeitenZahlMalVersionen>48</SeitenZahlMalVersionen>
    <Seitenzahlgesamt>48</Seitenzahlgesamt>
    <SeitenzahlInhalt />
    <SeitenzahlUmschlag />
    <Farbigkeit>44</Farbigkeit>
    <FarbigkeitInhalt />
    <FarbigkeitUmschlag />
    <PapierInnen>135g Innenteil</PapierInnen>
    <PapierUmschlag>250g Umschlag (matt, hochwertiger Qualitätsdruck, 4/4-farbig)</PapierUmschlag>
    <Endformat_mm_X>210</Endformat_mm_X>
    <Endformat_mm_Y>297</Endformat_mm_Y>
    <Datenformat_mm_X>216</Datenformat_mm_X>
    <Datenformat_mm_y>303</Datenformat_mm_y>
    <FormatUmschlag_x />
    <FormatUmschlag_y />
    <EndFormatUmschlag_x />
    <EndFormatUmschlag_y />
    <Falzart>0</Falzart>
    <Falzlauf />
    <gefendFormat_x />
    <gefendFormat_y />
    <BeschnittI>3</BeschnittI>
    <BeschnittU />
    <Bundstaerke>3</Bundstaerke>
    <vWd>0</vWd>
    <pWd>0</pWd>
    <vUV>0</vUV>
    <pUV>0</pUV>
    <Rillung>0</Rillung>
    <KissCut>0</KissCut>
    <Druckverfahren>Druck</Druckverfahren>
    <dataformat>pdf</dataformat>
    <Zusatzinfo>Schwarz</Zusatzinfo>
  </Artikel>
  <Optionen>
    <Veredelung>0</Veredelung>
    <Falzung>0</Falzung>
    <Ausrichtung>0</Ausrichtung>
    <Heften>0</Heften>
    <Nutung>0</Nutung>
    <Buendelung>0</Buendelung>
    <Leimung>0</Leimung>
    <Perforierung>0</Perforierung>
    <Sonderfarbe>0</Sonderfarbe>
    <Lochbohrungen_Ecken>0</Lochbohrungen_Ecken>
    <Nummerierung>0</Nummerierung>
    <Barcode>0</Barcode>
    <Hologramm>0</Hologramm>
    <Abheftvorrichtung>0</Abheftvorrichtung>
    <Cello>
      <Cellophaniert>0</Cellophaniert>
      <CelloArt>0</CelloArt>
    </Cello>
    <stanze>
      <StanzeForm>keine</StanzeForm>
      <StanzeOffset>0</StanzeOffset>
    </stanze>
    <Einschweissen>0</Einschweissen>
    <Fadenheftung>0</Fadenheftung>
    <Werbefolie>0</Werbefolie>
    <Ecken_abrunden>0</Ecken_abrunden>
    <RAL_Farbe>0</RAL_Farbe>
    <Gummiband_Verschluss>0</Gummiband_Verschluss>
    <HKS_Pantone>0</HKS_Pantone>
    <Lochung>0</Lochung>
    <PP_Deck>0</PP_Deck>
    <DeckBl_V>0</DeckBl_V>
    <DeckBl_V_H>0</DeckBl_V_H>
    <Praegung>0</Praegung>
    <Rubbelfeld>0</Rubbelfeld>
    <Magnetstreifen>0</Magnetstreifen>
    <Unterschriftsfeld>0</Unterschriftsfeld>
    <Magnetpunkt_Verschluss>0</Magnetpunkt_Verschluss>
    <Griffloch>0</Griffloch>
    <Verchromte_Buchecken>0</Verchromte_Buchecken>
    <Rueckentasche>0</Rueckentasche>
    <Visitenkartentasche>0</Visitenkartentasche>
    <Dreieckstasche>0</Dreieckstasche>
    <Kombitasche>0</Kombitasche>
    <CD_Tasche>0</CD_Tasche>
    <Radooesen>0</Radooesen>
    <Postkarten_indiv_personalisieren>0</Postkarten_indiv_personalisieren>
    <LED_Halogenbeleuchtung>0</LED_Halogenbeleuchtung>
    <Klima>1</Klima>
  </Optionen>
  <Zusatzkosten />
  <Dateien>
    <Dateiname>12345-999.pdf</Dateiname>
  </Dateien>
  <WF_Name>
    <WF_Name>12345-999.pdf</WF_Name>
  </WF_Name>
</MFK_XML> ```


Here´s the Code of the VBA:


``` Sub From_XML_To_XL()
    Dim xWb As Workbook
    Dim xSWb As Workbook
    Dim xStrPath As String
    Dim xFileDialog As FileDialog
    Dim xFile As String
    Dim xCount As Long
    On Error GoTo ErrHandler
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    xFileDialog.AllowMultiSelect = False
    xFileDialog.Title = "Select a folder"
    If xFileDialog.Show = -1 Then
        xStrPath = xFileDialog.SelectedItems(1)
    End If
    If xStrPath = "" Then Exit Sub
    Application.ScreenUpdating = False
    Set xSWb = ThisWorkbook
    xCount = 1
    xFile = Dir(xStrPath & "\*.xml")
    Do While xFile <> ""
        Set xWb = Workbooks.OpenXML(xStrPath & "\"& xFile)
        xWb.Sheets(1).UsedRange.Copy xSWb.Sheets(1).Cells(xCount, 1)
        xWb.Close False
        xCount = xSWb.Sheets(1).UsedRange.Rows.Count + 2
        xFile = Dir()
    Loop
    Application.ScreenUpdating = True
    xSWb.Save
    Exit Sub
ErrHandler:
    MsgBox "no files xml"
End Sub```




Read Excel checkbox from Python

$
0
0

I want to read data from an Excel sheet from a Python script and fill an XML file using the data read. Unfortunately the Excel sheet/form contains checkboxes and drop down lists. I was unable to get the value of the drop down list from its cell with the code below.

import openpyxl

excel_document = openpyxl.load_workbook('name.xlsx', keep_vba=True)

name_sheet1 = excel_document.get_sheet_names()[0]
sheet1 = excel_document.get_sheet_by_name(name_sheet1)
cell = sheet1['D38']
print(cell.value)

Does somebody know a way to parse Excel elements like checkboxes and drop down lists with Python?

Get Excel comment cell reference directly using Office.js

$
0
0

I need to read all the comments in an Excel worksheet with the related cell references, using Office.js.

I don't know in which cells the comments are, I'm able to access to Excel.CommentCollection object and read all the comments information, but I cannot find a way to get the comment cell reference, is there a way to get it?

Thanks

How to hide/encrypt Excel VBA cdo email password in code?

$
0
0

i use this method to send emails from Excel:

Dim Mail As New Message
Dim Config As Configuration
Set Config = Mail.Configuration

Config(cdoSendUsingMethod) = cdoSendUsingPort
Config(cdoSMTPServer) = "smtp.gmail.com"
Config(cdoSMTPServerPort) = 25
Config(cdoSMTPAuthenticate) = cdoBasic
Config(cdoSMTPUseSSL) = True
Config(cdoSendUserName) = "sender@gmail.com"
Config(cdoSendPassword) = "password123"
Config.Fields.Update

But as you can see the password is shown as a plain text in the code.

How can i hide/encrypt that line (password) or this part/module of my vba-code? (I've read something about to make a dll from the code, but don't know how.)

Thank You!

Is it possible to create a button activated macro to peform an accumulative sum in one cell then loop on itself everytime I press the button

$
0
0

I'm currently trying to create a yearly total that gets added on to every time i hit a button the problem is the code is trying to loop on itself.

AA5 = AA5+Z5

i also need the code to affect both Z and AA columns from Z5 and AA5 downwards.

Week 1 Z5 "200" AA5 "200"
week 2 Z5 "350" AA5 "550"
Week 3 Z5 "620" AA5 "1170"

just so every time i make a payment the total goes up but i don't wish to have a giant list of every week and what payment just the current week and the total paid all together. This is the macro i tried to record but failed.

`Sub Accumulate()
    Range("AA5").Select
    ActiveCell.FormulaR1C1 = "=RC+RC[-1]"
    Range("AA5").Select
End Sub`

I was wondering if it was possible or if i had to make two separate macros where the first would do the total in a third spot then say AB5 then the second macro will make AA5 = AB5 then manually preform both loops too separate buttons.

https://imgur.com/YiTgLkM

Converting Google sheets to Excel 2003 (.xls) using Apps Script

$
0
0

Currently, it seems Google has no way of converting Sheets to .xls format. So, I'm trying to use App Script to parse values from Sheet into a .XLS format. Here's the sample code below.

var sheet = SpreadsheetApp.openById('1...3f');
var sourceFolder = DriveApp.getFolderById('17..f');
sourceFolder.createFile("Test File",sheet.getSheets()[0].getDataRange().getDisplayValues(), MimeType.MICROSOFT_EXCEL_LEGACY);

Data in Sheets has headers looks like this: sample data

However after converted to .xls, it looks like this all in cell A1: Name,Age,Fred,30,Jane,25

I've tried using:

Drive.Files.get(fileId).exportLinks[MimeType.MICROSOFT_EXCEL_LEGACY]

But Google doesn't support it. Has to be MimeType.MICROSOFT_EXCEL. Any help will be appreciated.

Jexcel - Updating an excel with data

$
0
0

I've tried using Jexcel

to update an existing excel sheet as discussed in the Vogella tutorial.

Issue here is the data already present in the existing excel sheet is wiped out with the newly written excel data.

For example if I've this in the excel

<table>
<tr>
<td>1</td> <td>2 </td>
</tr>
<tr>
<td>3</td> <td>4 </td>
</tr>
<table>

and I want to add data to the new cell next to 2 and 4, like

<table>
<tr>
<td>1</td> <td>2 </td> <td>X </td>
</tr>
<tr>
<td>3</td> <td>4 </td> <td>Y </td>
</tr>
<table>

after the write program executed this is what I get

<table>
<tr>
<td> </td> <td>  </td> <td>X </td>
</tr>
<tr>
<td> </td> <td>  </td> <td>Y </td>
</tr>
<table>

Label label;
label = new Label(column, row, s, times);
sheet.addCell(label);

This is adding the cell at the specified column and row but wiping out the rest of the excel data.

How can I add data to the existing excel keeping the data?

Following is the program(Reference: Vogella). Excel sheet already has data in 20 rows and first 2 columns, am trying to add data on the 3rd column for 20 rows package excel;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

import jxl.CellView;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.format.UnderlineStyle;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class WriteExcel {

    private WritableCellFormat timesBoldUnderline;
    private WritableCellFormat times;
    private String inputFile;

    public void setOutputFile(String inputFile) {
        this.inputFile = inputFile;
    }

    public void write() throws IOException, WriteException {
        File file = new File(inputFile);
        WorkbookSettings wbSettings = new WorkbookSettings();

        wbSettings.setLocale(new Locale("en", "EN"));

        WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings);
        workbook.createSheet("Report", 0);
        WritableSheet excelSheet = workbook.getSheet(0);
        createLabel(excelSheet);
        createContent(excelSheet);

        workbook.write();
        workbook.close();
    }

    private void createLabel(WritableSheet sheet) throws WriteException {
        // Lets create a times font
        WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
        // Define the cell format
        times = new WritableCellFormat(times10pt);
        // Lets automatically wrap the cells
        times.setWrap(true);

        // Create create a bold font with unterlines
        WritableFont times10ptBoldUnderline = new WritableFont(
                WritableFont.TIMES, 10, WritableFont.BOLD, false,
                UnderlineStyle.SINGLE);
        timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
        // Lets automatically wrap the cells
        timesBoldUnderline.setWrap(true);

        CellView cv = new CellView();
        cv.setFormat(times);
        cv.setFormat(timesBoldUnderline);
        cv.setAutosize(true);

    }

    private void createContent(WritableSheet sheet) throws WriteException,
            RowsExceededException {

        Integer salary = 1000;
        // Now a bit of text
        for (int i = 0; i < 20; i++) {
            // third column
            addLabel(sheet, 2, i, salary.toString());

            // WritableCell cell = sheet.getWritableCell(2, i);
            // if (cell.getType() == CellType.LABEL) {
            // Label l = (Label) cell;
            // l.setString("modified cell");
            // }
            salary += 1000;
        }

    }

    private void addLabel(WritableSheet sheet, int column, int row, String s)
            throws WriteException, RowsExceededException {
        Label label;
        label = new Label(column, row, s, times);
        sheet.addCell(label);
    }

    public static void main(String[] args) throws WriteException, IOException {
        WriteExcel test = new WriteExcel();
        test.setOutputFile("c:/temp/lars.xls");
        test.write();
        System.out
                .println("Please check the result file under c:/temp/lars.xls ");
    }
}

VBA to take info from one sheet and copy it to other sheet

$
0
0

My sheet_one looks like this:

    2020-01-31
A   2
B   3
C   10

My sheet_two looks like this:

    2019-12-31  2020-01-31  2020-02-29  2020-03-31  2020-04-30  2020-05-31  2020-06-30  2020-07-31  2020-08-31  2020-09-30  2020-10-31  2020-11-30  2020-12-31
A                                                   
B                                                   
C                                                   

How can I copy the information from the first sheet to the second?

Thank you for your suggestions.


Excel custom function add using VBA for trim the front and tail of the cell spaces [closed]

$
0
0

This is what I used code in VBA to create excel custom function.

Sub TrimExample1()
    MsgBox Trim(Range("A1"))
End Sub

Can I convert this function to excel formula?

Separating Texts in a single cell into multiple cells with Excel/Excel VBA

$
0
0

I collected data from web scraping using python but it turns out all the review comments in one page is compiled into a single cell in excel. Is there any excel features or Excel VBA functions/codes I could use to separate each data into its own cell?

[ Mari Russell ,
Olivia ,
Katie Jade ,
Eladi Starr ,
Angela Graham ,
Hillary ,
Ann Hudak ,
Dag107 ,
Sarah Summerbell ,
Kelly Sill ,
Lynette Starleper ,
KatherineC605 ,
Rachel ,
Odalis Melgar ,
Alisa R ,
Gina G Carey ,
Donna Julian ,
Sharikka Fraylon ,
Elizabeth Marcenaro ,
Shannon Buzzell ]

Update the format of an Excel file in SSIS script task

$
0
0

I have an SSIS package which runs an SQL script and puts the results into an Excel file; the file at the beginning has just a header row with bolded column names.

What I have found is that, no matter how my data is formatted in my data flow tasks, my numbers end up going into the Excel file as text.

Could somebody please help me with a script task that will update the columns O and P to be displayed correctly as currency, with the £ symbol.

This is how they look after SSIS imports the data:

enter image description here

This is how I require them to look:

enter image description here

VBA First time creating Class

$
0
0

I'm currently working on a VBA project. I only have experience in the basics of VBA (No OOP, just functions and subs) and C#.

Today I am trying to create my first class but i run into an error.

This is how the class looks like:

'CLASS Disponent

 Private Sub Class_Initialize()
      m_dispocode = 1
      m_name = Unknown
      m_suppliers
      m_materials
      SetID
End Sub

Private m_materials As New ArrayList
Private m_suppliers As New ArrayList
Private m_name As String
Private m_dispocode
Private m_id As String

Property Get Id() As Integer
    Id = m_id
End Property

Property Get Suppliers(value As Integer) As String
If value >= 0 And value < m_suppliers.Count Then
        Suppliers = m_suppliers(value)
Else
    Err.Raise ERROR_INVALID_INDEXING, "ReadWorksheet", "The indexer used in the arraw is out of bounds"
End If
End Property

Property Let Suppliers(supp As String)
    m_suppliers.Add supp
End Property

Property Get Dispocode() As Integer
 Dispocode = m_dispocode
End Property

Property Let Dispocode(dispcode As Integer)
If dispcode > 0 And dispcode < 1000 Then
    m_dispocode = dispcode
Else
    Err.Raise ERROR_INVALID_DISPOCODE, "ReadWorksheet", "The value must be between 1 (incl) and 999 (incl)"
End If
End Property

Property Get name() As String
    name = m_name
End Property

Property Let name(name As String)
    If Len(name) > 3 Then
    m_name = name
    Else
    Err.Raise ERROR_INVALID_NAME, "ReadWorksheet", "The name must be at least 3 letters long"
End Property

Property Get Materials(indexof As Integer) As ArrayList
If indexof >= 0 And indexof < m_suppliers.Count Then
    Materials = m_materials(indexof)
Else
    Err.Raise ERROR_INVALID_INDEXING, "ReadWorksheet", "The indexer used in the arraw is out of bounds"
End If
End Property

Property Let Materials(materialnum As String)
     m_materials.Add materialnum
End Property

Public Sub SetID()
    m_id = m_name & m_dispocode
End Sub

And this is how I try to create my objects in a SUB in a normal Module:

Sub GenerateDisponents()
Dim last_row As Long
last_row = Sheets("Disponents").Cells(Rows.Count, 1).End(xlUp).Row

Dim Dispos As New Collection

For i = 1 To last_row
    Dim temp As New Disponent

    Dim name As String
    name = Sheets("Disponents").Range("B"& i).value
    Dim code As Integer
    code = Sheets("Disponents").Range("A"& i).value

    temp.name = name
    temp.Dispocode = code

    Dispos.Add temp


MsgBox ("DONE")
End Sub

When I try to run GenerateDisponents sub I get the following error on the Let Materials property: "Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, a ParamArray, or an invalid Set final parameter."

For the early binding I use the following reference: C:\Windows\Microsoft.NET\Framework\v4.0.30319.\mscorlib.dll.

Do you guys have any idea why my code isn't working?

I am sure its full of mistakes because it's my first time trying using classes in VBA.

Thanks for the help in advance!

SaveAS file and not open it

$
0
0

I have a file with 2 buttons, one to "Show questionnaire" and one to "Show Answers""Show questionnaire" shows a questionnaire with questions for people to answer "Show Answers" shows the answers to each question

At the moment when the file is first opened the "Show Answers" button is hidden

Then when someone finishes the questionnaire and submits their answers the following code should run

Worksheets("Questionnaire").Activate
 ActiveSheet.Buttons("Button 3").Visible = True

ActiveWorkbook.SaveAs Filename:="Folder where a copy of the questionnaire with the answers is saved") & ".xlsb", FileFormat:=xlExcel12, Password:="123", CreateBackup:=False

Worksheets("Questionnare").Activate
ActiveSheet.Buttons("Button 3").Visible = False

MsgBox "Thank you for your submission", vbOKOnly
ActiveWorkbook.Close

This code makes the button visible, then creates a copy and saves it into a folder with a password (so the button is available only in that new file for people who have the password to the file) and then makes the button non visible in the original file so when a new person tries to answer the questionnaire the "Show Answers" button does not appear for them.

My issue is that at the moment what the code actually does is it makes the button visible, saves the file, opens the new file and then makes the button non visible in the new file rather than in the original file.

How can I stop the "SaveAS" option from opening the new workbook after it saves it? how can I make it make the "Show Answers" button non visible in the original file instead?

Viewing all 88178 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>